Important Bits

How to use reselect wrong

December 23, 2018

Using an identity function for resultFunc

If you were going to do:

const selectSomething = createSelector(
  R.prop('something'),
  R.identity
)

You are typing too much, and your selector can be

const selectSomething = R.prop('something')

Why is this wrong?

The point of reselect is to cache the results of operations performed in the resultFunc. In this case, that function is R.identity, which returns whatever object was passed to it. There’s nothing to cache since an object is being passed straight through R.identity with no changes, so createSelector is redundant and can be removed to improve the clarity of the program.


Adam Sullovey

Written by Adam Sullovey, powered by Gatsby.
Find me on codepen, github, or at Toronto meetups.