3 ms·
Also, when you do use Redux, as in your nesting example don't pass props through components that don't have any need for them except they propagate the prop to
by Androider 9y ago
Also, when you do use Redux, as in your nesting example don't pass props through components that don't have any need for them except they propagate the prop to someone else. It's absolutely fine to connect() a component deeper in the hierarchy. Passing everything down is an anti-pattern with Redux, separation of concerns still applies and the props of a component defines the API, don't clutter that API with unrelated things.
Components only receiving props that they themselves need has kept things clean in our massive codebase, and allows you to effortlessly move things about and easily re-use components wherever it makes sense.
- acemarke 9y agoYep, absolutely. See the Redux FAQ entry on "connecting multiple components" for more info [0] . I also discussed how connecting more components affects performance in my blog post "Practical Redux, Part 6 - Connected Lists, Forms, and Performance" [1], and there's many additional articles that discuss connected components and performance concerns as well [2]. [0] http://redux.js.org/docs/faq/ReactRedux.html#react-multiple-components http://redux.js.org/docs/faq/ReactRedux.html#react-multiple-... [1] http://blog.isquaredsoftware.com/2017/01/practical-redux-part-6-connected-lists-forms-and-performance/ http://blog.isquaredsoftware.com/2017/01/practical-redux-par... [2] https://github.com/markerikson/react-redux-links/blob/master/react-performance.md#redux-performance https://github.com/markerikson/react-redux-links/blob/master...
- prance 9y agoI don't agree with the view that a component doesn't need a prop "itself" if it "only" passes it on to a child component. That child component is a part of the parent. If one decided that e.g. the child is too simple to warrant to be its own component and inlined its render() content in the parent instead, suddenly its used props would be needed by the parent "itself". Another thing to consider is that one tightly couples components to stores when connecting. So reusability of these components is hampered.
- pedalpete 9y agoIf was my understanding that if a component has a prop which changes, even if that prop is passed down the tree, the component will still update. This is one way I use redux, the connector watches for changes in state and then updates the component directly, rather than passing props down the tree.
- deleted 9y ago[deleted]