DEV Community

Alexandre Gomes
Alexandre Gomes

Posted on

Is anyone still actively using reselect createSelector?

In 2021 where the community has switched to hooks, and the official useSelector as a way to write/compose selectors, that have caching (to some extent) of (possibly) derived data from props/state, is anyone still using reselect for selectors composition?

  • If you got into react development in the time of hooks, is this something you've heard about? Did you experience gotchas with useSelector?
  • If you decided against using it or found an alternative, how do you deal with
    • memoization
    • caching
    • derivation and composition

I'm planning a whole optimization series on primitive vs. object types in JS, derivation, memoized selectors as well as advanced memoization patterns and am trying to figure out what's the state and general JS developers sentiment on reselect usage these days, but most importantly, compare the alternatives to give the most comprehensive overview on memoization techniques.

Thank you all in advance for your answers!

Top comments (1)

Collapse
 
vldmrgnn profile image
Vlad • Edited

Hello, I am using reselect heavily and I am ok with it.
The stack from this pov is React Redux + Redux Saga + Reselect;

Now and then I am passing variables like this:

import { createSelector } from 'reselect';
...
const getStuff = state => state.stuffReducer; 
const sParams  = (state, someIds = [] ) => someIds; // <- as variables;

export const someSelector = createSelector(
    sParams,
    getStuff,    
    (someIds, stuff) =>{
        ...
    }
);
Enter fullscreen mode Exit fullscreen mode

(perhaps it could be optimized when using params, memoize those too with no extra boiler-plate)

Then import the selector in saga using "select" or in component using "useSelector" and that's it.

When needed I make use of "reselect-map" ( github.com/HeyImAlex/reselect-map ) which is awesome in some scenarios.

I find it very comfortable combining selectors in reselect.

Good luck and keep us informed on this!