December 23, 2018
How to use reselect wrong
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.