#575·reselect

Question: does reselect help with performance on higher-order functions?

Author: lindapaisteCreated May 13, 2022Updated Apr 12, 2026

I am writing a higher-order function as a helper for writing selectors on a Redux Toolkit slice and I'm wondering if it makes sense to use reselect here or not.

Here is how that might look with and without using createSelector:

typescript
const subSelectV1 = <T>(subSelector: (subState: MySliceState) => T) =>
    (state: RootState): T => subSelector(rootState.mySlice);

const subSelectV2 = <T>(subSelector: (subState: MySliceState) => T) =>
    createSelector(
        (state: RootState): MySliceState => state.mySlice,
        subSelector
    );

Pros: In V2 the subSelector function would not get re-evaluated at all if there are changes to other slices but not to state.mySlice.

Cons: There is maybe some overhead associated with the memoization and caching?

subSelector here would be a simple selector that just accesses data from the state and does not transform it. I would then use the resulting selector as an input selector to createSelector in other places.


The goal is simply to save me from having to write state: RootState and state.mySlice everywhere when I am defining a whole bunch of selectors.

I can write:

typescript
export const selectSpecificThing = subSelect(state => state.someProperty);

Instead of:

typescript
export const selectSpecificThing = (state: RootState) => state.mySlice.someProperty;