Registry / testing / re-reselect

re-reselect

JSON →
library5.1.0jsnpmunverified

A lightweight wrapper around Reselect that provides deeper memoization and cache management for selectors. Current stable version is 5.1.0. Since Reselect v5, many re-reselect features are now native in Reselect, but re-reselect continues to offer backward compatibility and custom caching strategies. It maintains a cache of Reselect selectors keyed by a user-defined key selector, allowing different calls with different arguments to hit separate caches. Compared to bare Reselect, re-reselect prevents cache invalidation when switching between different argument values, making it ideal for sharing selectors across multiple component instances or sequentially calling selectors with varying parameters.

npm install re-reselect
INSTALL
IMPORT
SIG · RE-RESELECT
R
re-reselect
testingjavascriptv5.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createCachedSelector
import { createCachedSelector } from 're-reselect';
import createCachedSelector from 're-reselect';
re-reselect exports createCachedSelector as a named export, not a default export.
createStructuredCachedSelector
import { createStructuredCachedSelector } from 're-reselect';
const createStructuredCachedSelector = require('re-reselect').createStructuredCachedSelector;
CommonJS require of named export works, but ESM named import is preferred in modern projects.
FlatCacheObject
import { FlatCacheObject } from 're-reselect';
Type-only import: import type { FlatCacheObject } from 're-reselect'; Available when using TypeScript.

Demonstrates createCachedSelector with a keySelector based on libraryName, showing cache retention across different argument values.

import { createCachedSelector } from 're-reselect'; const getUsers = (state) => state.users; const getLibraryId = (state, libraryName) => state.libraries[libraryName]?.id; const getUsersByLibrary = createCachedSelector( getUsers, getLibraryId, (users, libraryId) => users.filter(user => user.libraryId === libraryId) )( (state, libraryName) => libraryName ); const state = { users: [ { id: 1, libraryId: 10 }, { id: 2, libraryId: 20 }, ], libraries: { react: { id: 10 }, vue: { id: 20 }, }, }; const reactUsers = getUsersByLibrary(state, 'react'); const vueUsers = getUsersByLibrary(state, 'vue'); const reactUsersAgain = getUsersByLibrary(state, 'react'); console.log(reactUsers === reactUsersAgain); // true - cache hit
Debug
Known issues
gotchare-reselect v5+ requires reselect v5 as a peer dependency. Using older reselect versions may cause unexpected behavior or TypeScript errors.
fix
yarn add reselect@^5.0.0 or npm install reselect@^5.0.0
affects: >=5.0.0
deprecatedFrom reselect v5, many re-reselect features are natively available. Re-reselect is maintained for backward compatibility but may not receive new features.
fix
Consider switching to native reselect createSelector with custom memoize options if you don't need backward compatibility.
affects: >=5.0.0
gotchaThe keySelector is required and must return a valid cache key. If it returns undefined, every call will create a new selector without caching.
fix
Ensure keySelector returns a primitive (string, number) or a value compatible with the chosen cache object.
affects: *
breakingIn re-reselect v4, the default cache object was changed from LruCacheObject to FlatCacheObject by default, which may break code relying on LRU eviction behavior.
fix
Pass { cacheObject: new LruCacheObject({ maxSize: 5 }) } as option to restore LRU behavior.
affects: >=4.0.0 <5.0.0
gotchaWhen using TypeScript, the createCachedSelector type inference may not be perfect with complex selectors. You may need to manually type the keySelector or use 'as any' in some edge cases.
fix
Cast keySelector return type explicitly or use type assertions with caution.
affects: *
Errors
Common errors & fixes
TypeError: (0 , re_reselect_1.createCachedSelector) is not a function
Default import used instead of named import. re-reselect does not have a default export in ESM.
fix
Use named import: import { createCachedSelector } from 're-reselect';
Cannot find module 're-reselect' or its corresponding type declarations.
Missing TypeScript types or incorrect version. re-reselect ships types, but may need @types/reselect installed separately.
fix
Install reselect and its types if using TypeScript: npm install reselect @types/reselect re-reselect
Uncaught Error: re-reselect expects 'reselect' as a peer dependency but is missing.
Missing peer dependency reselect. re-reselect requires reselect installed alongside.
fix
Install reselect: npm install reselect
Selector creators (createCachedSelector) expect a keySelector function as second argument, but got undefined.
KeySelector not provided or returned undefined. KeySelector is required and must return a valid key.
fix
Pass a keySelector function that returns a primitive (e.g., (state, arg) => arg.id).
Upgrade
Version history
5.1.0latest on npm
Audit
Dependencies
reselectrequiredpeer dependency - re-reselect wraps reselect and requires it to be installed separately
Agent activity
4 hits · last 30 days
node
4
Resources
re-reselect — npm install re-reselect · libregistry