DEV Community

Discussion on: React Beginner Question Thread ⚛

Collapse
 
cyan33 profile image
Chang Yan

You use the react-redux utility with the mapStateToProps function, which does the thing as it's called, so that whenever the state (of the store) changes, the props changes as well. And it triggers the re-render of react components.

Collapse
 
viniciuscamargo profile image
Vinicius Camargo

Thanks, Chang! I think I wasn't clear enough, I'm sorry! I meant the details of the implementation of such patterns.

Thread Thread
 
dan_abramov profile image
Dan Abramov

Internally React Redux works by calling store.subscribe() when the component mounts. Every time the Redux store changes, the subscription callback fires. Inside it, React Redux calls React setState() by taking Redux store state and passing it through mapStateToProps().

Here’s a simple version: gist.github.com/gaearon/1d19088790...

Thread Thread
 
viniciuscamargo profile image
Vinicius Camargo

Thank you so much! That's exactly what I wanted to know :D

Thread Thread
 
cyan33 profile image
Chang Yan

Thanks Dan, the code example is really helpful. Also I found your video talk about react-redux very inspiring and straight-forward as well. For those who are interested, you can go to
youtube.com/watch?v=VJ38wSFbM3A. <3