Using Redux with Components
Instead of having to manage the store subscribtions manually we can use react-redux to connect our store to React components. To demonstrate how this works, let's take a look at the counter example.
Counter Example
We start by building out a counter component. The component will be responsible for keeping track of how many times it was clicked, and displaying the amount.
The template syntax should be familiar by now, displaying a counter value, and handling some click events. Lets take a look at the use of connect
.
mapStateToProps
: connect will subscribe to Redux store updates. Any time it updates, mapStateToProps will be called. It's result must be a plain object. Which will then be passed to the component as props.
Full Example
Last updated
Was this helpful?