Skip to main content

Common Mistakes

A somewhat common mistake is to write an input selector that extracts a value or does some derivation, and a result function that just returns its result:

// ❌ BROKEN: this will not memoize correctly, and does nothing useful!
const brokenSelector = createSelector(
[(state: RootState) => state.todos],
todos => todos
)

Any result function that just returns its inputs is incorrect! The result function should always have the transformation logic.

Similarly:

// ❌ BROKEN: this will not memoize correctly!
const brokenSelector = createSelector(
[(state: RootState) => state],
state => state.todos
)