Thoughts On You Might Not Need Redux Pt.V
I heavily considered calling this “You Might Not Need Redux, Redux”, but was able to resist the pun.
All three of the trade offs that come with using Redux all can be avoided, if that’s best for the project, if a developer just considers the advantages that React, without Redux, has to offer.
When someone said to me:
“When I use React I have a lot of props going up and down the tree of components. How do you avoid that?”
I told them, I look for the highest component that needs to know about any given piece of state and store state there, not any higher. I don’t automatically give the root component, or any other component for that matter, knowledge of other component’s state, just because I ask myself “does this component need to know about it”, more times than not only the component that will have the state change and one component above it will need to know about given state. If this is the case, as it often is with smaller single paged apps, I house some local state, have that component take care of itself, and then give the rest of the behavior to the component one level up.
I sometimes, however, find, that a few different components, with behavior that is not similar enough to be lumped together need knowledge of one another’s state and can only get it from a component a few levels up, in that case, I decide, I might need Redux.
