DEV Community

sunflowerseed
sunflowerseed

Posted on

How to make a React / Redux App able to get a value from a sub-component?

I have this simple Counter using React / Redux:

https://stackblitz.com/edit/react-kkcgza?file=App.js

It is said that Redux can let any component get a value? (meaning Redux can let us decide where the destinations are for our state).

Can someone tell me how to let the App component get the count value and show it? (besides letting the Counter show it) -- can you edit online and fork a copy if you can?

Top comments (1)

Collapse
 
keirk profile image
Keir Kettle • Edited

The thing to bear in mind with React is the data flow is top down - App passes data downwards to Counter via props. So if App is interested in the data then either:

  • It could contain the logic (i.e. it becomes the 'container') - see medium.com/@dan_abramov/smart-and-...

  • You could connect the App component to the Redux store (using the connect hoc)