reduxjs / react-redux

Official React bindings for Redux
https://react-redux.js.org
MIT License
23.37k stars 3.37k forks source link

Is this a good idea to connect nested components? #159

Closed tadjik1 closed 9 years ago

tadjik1 commented 9 years ago

On each page on my website I have many components and I don't want to control fetching and grabing data from store for every component just in one "smart" top-level component. So I want to connect nested components too. Is this a good pattern? Will I meet a perfomance troubles with this way of connect? What I need to know about connected components behavior for avoiding troubles?

gaearon commented 9 years ago

Please see https://github.com/rackt/redux/issues/419.

Both approaches are fine, and having nested connect() components is actually going to give you more performance. The downside is they're slightly more coupled to the application and slightly harder to test, but that may not be a big issue.

tadjik1 commented 9 years ago

thanks!

esamattis commented 9 years ago

I recommend usage of redux-batched-updates as it can avoid some serious headaches. See 3.0.0 release notes. It will also improve performance in some cases.

natevw commented 7 years ago

I started wondering the same thing, whether connect was intended to be used on ± every component individually, or only on the top level component. The link @gaearon gives is broken, I think https://github.com/reactjs/redux/issues/419 is the correct thread to refer to for more discussion.

markerikson commented 7 years ago

The current answer to this question is in the Redux FAQ. See http://redux.js.org/docs/faq/ReactRedux.html#react-multiple-components . My recent blog post at http://blog.isquaredsoftware.com/2017/01/practical-redux-part-6-connected-lists-forms-and-performance/ also discusses the idea of multiple connected components and performance.

alexmcmillan commented 7 years ago

@gaearon update for rotten link: https://github.com/reactjs/redux/issues/419

PabloDinella commented 5 years ago

The current answer to this question is in the Redux FAQ. See http://redux.js.org/docs/faq/ReactRedux.html#react-multiple-components . My recent blog post at http://blog.isquaredsoftware.com/2017/01/practical-redux-part-6-connected-lists-forms-and-performance/ also discusses the idea of multiple connected components and performance.

Updated link: https://redux.js.org/faq/react-redux#should-i-only-connect-my-top-component-or-can-i-connect-multiple-components-in-my-tree