re-reselect

Enhance Reselect selectors with per-argument memoization and cache management.

Library
npm
v5.1.1
1,092stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
72/100Good
Development Activity88
Maintenance64
Community48
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
74/100Good
Architecture74
Code Quality78
Innovation66
Learning Curve76

re-reselect is a lightweight wrapper around Reselect that fixes a well-known limitation: standard Reselect selectors have a memoization cache of exactly one, so switching between arguments (e.g. calling the same selector with different IDs) invalidates the cache on every call. re-reselect’s createCachedSelector instead forwards each distinct set of arguments to its own internally cached Reselect selector, keyed by a keySelector you define, so previously computed results for each argument combination are retained instead of recomputed.

This makes it straightforward to share one selector definition across multiple component instances (e.g. one selector per list item, keyed by id) or across sequential calls with a few different arguments, without either duplicating selector logic or losing memoization. With 1,094 GitHub stars and continued active maintenance, it remains a common companion to Reselect and Redux even as Reselect v5 has natively absorbed some of its original functionality.

What You Get

  • createCachedSelector, a drop-in replacement for Reselect’s createSelector that adds a keySelector argument to control cache-key resolution
  • Per-key memoization so the same selector definition retains separate cached results per argument (e.g. per id, per prop) instead of invalidating on every argument change
  • createStructuredCachedSelector for structured/object-shaped selector outputs with the same per-key caching behavior
  • Pluggable cache objects/strategies so consumers can swap in custom cache implementations (e.g. LRU, size-limited) instead of the default unbounded cache
  • Full TypeScript typings matching Reselect’s own selector typing conventions
  • Backward-compatible support for Reselect v5+, for teams that adopted re-reselect before Reselect’s own native custom-memoization options existed

Common Use Cases

  • Sharing one selector definition across multiple component instances that each pass a different id/prop, without losing memoization for any of them
  • Retaining cached results when a selector is called sequentially with a small, rotating set of different arguments (e.g. paginated or filtered views)
  • Joining several near-identical selectors that only differ by argument into a single cached selector definition
  • Applying a custom cache eviction strategy (size-limited, TTL-based) to selector memoization instead of an unbounded cache

Under The Hood

Architecture - The core (src/index.js, src/reselectWrapper.js) wraps Reselect’s createSelector in a factory that, given a keySelector, maintains an internal map from computed cache keys to individually memoized Reselect selector instances. createCachedSelector and createStructuredCachedSelector (src/createCachedSelector.js, src/createStructuredCachedSelector.js) are thin entry points over this shared wrapper, while src/cache/ implements the pluggable cache-object interface so the key-to-selector map’s eviction strategy can be swapped out.

Tech Stack - TypeScript source built with Rollup into CJS/ESM/UMD bundles plus type declarations, tested with Vitest including dedicated bundle-verification tests (test-bundles/) that snapshot-test each of the three published bundle formats independently. Reselect itself is a peer dependency rather than bundled, keeping re-reselect thin and aligned with whatever Reselect version the host app uses.

Code Quality - The test/ directory contains 16 test files, plus a separate test-bundles/ suite that runs the same behavioral tests against the actual built CJS, ES, and UMD outputs — catching bundling regressions that source-only tests would miss. The project uses simple-git-hooks, Prettier, and tsc --noEmit type-checking wired into its prepare/release scripts, and ships a CHANGELOG.md maintained via Changesets, indicating disciplined release hygiene.

API Design - createCachedSelector is designed as a near drop-in replacement for Reselect’s createSelector, adding only the keySelector concept, which keeps the learning curve minimal for anyone already using Reselect. The library is explicit in its own README about which of its original value proposition Reselect v5 has since absorbed natively, which is an unusually honest and useful signal for API consumers deciding whether they still need the wrapper.

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

Search