Reselect is a Selector library for Redux

Reselect is a Selector library for Redux
Average rating: 0
(0 votes)

A ‘store’ is one of the Redux core concepts, and when you use Redux it’s vital to understand how to structure the data in this store. To simplify your task, we’re reminding you about Reselect, a popular library that provides a convenient way of getting values from a store in a React-Redux application. To clarify, Reselect is a Selector library for Redux, with memoization ability. 

In Redux a selector is a piece of logic that gets a specific piece of state from the store. Also, a selector can compute data from a given state, allowing the store to keep only basic raw data.

When you use the createSelector() function, it memoizes an output of every input selector and recalculates the resulting value only if any of the input selectors changes its output.

Reselect is a memoized selector function, composed of selectors, that returns something you want in your component’s props.

If you create selectors with Reselect, you’ll get a few benefits in terms of developer experience and performance:

  • Selectors created using Reselect’s createSelector function are memoized. The function remembers the arguments passed-in the last time it was invoked and doesn’t recalculate if the arguments are the same. A selector is not recomputed unless one of its arguments changes.
  • Reselect selectors can be easily composed/chained together. They can be even used as input to other selectors. Each selector stays small and focused on one task.
  • Selectors can compute derived data, allowing Redux to store the minimal possible state.

Learn about

A few tips for using Reselect library:

  1. Use createSelector() from Reselect to create a selector, if it transforms value from the state in any way.
  2. Avoid curried selectors. You can pass all the arguments you need using the second argument of a selector.
  3. Be careful with dispatching actions to the store from lifecycle functions. In general, avoid doing this. If you face with it, try to compare props manually before dispatching an action.

Read more about Reselect on the project’s open source page.

Rate this article, if you like it

Thanks! You’ve rated this material!

Got a project? Let's discuss it!

*By submitting this form you agree with our Privacy Policy.

Mailing & Legal Address

Syndicode Inc. 340 S Lemon Ave #3299, Walnut CA, 91789, USA

Visiting & Headquarters address
Kyiv Sofiivska 1/2a, 01001, Kyiv, Ukraine
Dnipro Hlinky 2, of. 1003, 49000, Dnipro, Ukraine
Email info@syndicode.com
Phone (+1) 9035021111