Why redux suggests to only connect to top level components?

后端 未结 5 434
悲哀的现实
悲哀的现实 2020-12-25 12:53

I\'m new to redux and react-redux, in the mean time I am trying to make a redux app.

I don\'t understand the statement on redux document:

Then

5条回答
  •  感情败类
    2020-12-25 13:42

    Reading the latest answers as of when I post my answer here, I'd like to further add to the consensus of having each component connected using the official Redux style guide:

    Prefer having more UI components subscribed to the Redux store and reading data at a more granular level. This typically leads to better UI performance, as fewer components will need to render when a given piece of state changes.

    For example, rather than just connecting a component and reading the entire array of users, have retrieve a list of all user IDs, render list items as , and have be connected and extract its own user entry from the store.

    This applies for both the React-Redux connect() API and the useSelector() hook.

提交回复
热议问题