Reselect

Memoized selector functions for deriving data from Redux (or any) state

Library
npm
v5.3.0
19,005 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
86 /100 Excellent
Development Activity 96
Maintenance 84
Community 64
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
80 /100 Excellent
Architecture 82
Code Quality 85
Innovation 78
Learning Curve 75

Reselect is a small library for creating memoized “selector” functions that compute derived data from state. Selectors built with createSelector only recompute when their input values actually change, and return the same reference otherwise — which is essential for libraries like React-Redux that rely on reference equality to skip unnecessary re-renders.

While most commonly paired with Redux (and bundled by default in Redux Toolkit), Reselect works with any plain JavaScript state tree. Version 5 added pluggable memoization strategies (lruMemoize, weakMapMemoize, experimental autotracking), development-only stability and identity-function checks, and significantly improved TypeScript performance for deeply nested selectors.

What You Get

  • createSelector for composing memoized selectors from one or more input selectors and a result function
  • createSelectorCreator for building custom selector factories with alternate memoization (lruMemoize, weakMapMemoize, or a custom function)
  • createStructuredSelector for building an object of selectors that maps directly onto a shape of derived state
  • Development-only inputStabilityCheck and identityFunctionCheck helpers that warn about common selector-authoring mistakes

Common Use Cases

  • Deriving filtered/sorted/computed lists from Redux state without recalculating on every render
  • Preventing unnecessary React-Redux component re-renders by returning stable references when derived data hasn’t changed
  • Composing complex derived state from multiple smaller, reusable selectors
  • Adding development-time warnings for selectors with unstable inputs or accidental identity result functions

Under The Hood

Architecture — createSelector (in createSelectorCreator.ts) wraps a chain of “input selectors” and a final “result function”: on each call it runs every input selector, compares the extracted values against the previous call’s inputs (via the configured argsMemoize), and only invokes the result function when at least one input has changed, otherwise returning the cached prior result by reference. createStructuredSelector builds on the same primitive to produce a selector whose output is a plain object assembled from a map of named sub-selectors.

Tech Stack — Pure TypeScript with zero runtime dependencies beyond its own memoization implementations. Reselect ships three interchangeable memoization strategies as separate modules — lruMemoize (a small LRU cache, the default), weakMapMemoize (tree-structured caching keyed by object identity via WeakMap, unbounded by size), and an experimental autotracking-based memoizer — selectable per-selector via createSelectorCreator’s options.

Code Quality — Tests are organized per-feature under test/ (lruMemoize.test.ts, identityFunctionCheck.test.ts, createStructuredSelector.withTypes.test.ts, etc.), plus a dedicated examples.test.ts that exercises the README’s own usage examples and doc-site FAQ snippets (docs/examples/FAQ/howToTest.test.ts), keeping documentation and tests in sync. Coverage is tracked via Coveralls and CI runs a dedicated build-and-test-types workflow to catch TypeScript regressions specifically.

API Design — The core createSelector([inputSelectors], resultFn) shape is minimal and composable — selectors can be passed as inputs to other selectors, letting complex derived state be built from small, independently testable pieces. Development-mode-only checks (inputStabilityCheck, identityFunctionCheck) are a notable DX touch: they catch two of the most common selector-authoring mistakes (unstable inputs, forgetting the result function) with console warnings in dev builds only, at no cost in production.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers