Why redux suggests to only connect to top level components?

后端 未结 5 411
悲哀的现实
悲哀的现实 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:21

    The answer is in this section from your excerpt of the docs:

    While technically you can connect() any component in your app to Redux store, avoid doing this too deeply, because it will make the data flow harder to trace.

    One of the core principles of Redux is data should generally flow from the top down, i.e. it should be unidirectional. If you connect too many lower level components, your data flow is no longer unidirectional. The main consequence of this is that it is much easier to have inconsistent state among your components.

    When going top-down, which is what naturally happens when you only connect a limited number of high level components, it is much harder to create situations where you have inconsistent state, hence the advice in the docs.

提交回复
热议问题