I am new to react and redux. I have a scenario where there are nested components like this.
A > B > C > D
There is a property used in A component and it will be used in D component. So, I have two approaches:
- Get state from redux store in component A and then pass it along as props to all it's child components even though it will be used only in D component.
- I should connect to redux store in component D and fetch that property from there.
What is the correct approach?
I would suggest if you are already using redux in your app then set the property in the redux store and fetch it in the component D.
But if the work flow is really simple and all the data is fetched from a single source per view, you can avoid redux as it is for complex state management.
As Dan Abramov, author of redux says in this issue
He has also articulated a nice rule of thumb to follow on reddit
I do it this way:
He has even tweeted regarding this:
So in simple words:
You can use
connect()
at any level. Doing so makes the component smart, since it knows where its props come from. A dumb component just has props, and they could come from anywhere. A smart component is coupled to redux; a dumb component is not.