Sunday, October 01, 2017

Connecting Redux states and actions to a React component

Connecting states and actions from a Redux store to a React component is quite straightforward. While many developers use shortcut techniques to do it, I prefer to use the following format:

What this is saying basically is that somewhere we have a component called ProductList, and I would like to expose an action creator, called fetchProducts, and a state (possibly a state altered by this action creator), called products.

Note that I made use of an ES6 technique called object destructuring to shorten state.products into products, as I am only interested in that particular state. This technique is so common in this context that it is perfectly conventional to map states like this.
Post a Comment