# Reselect — Memoized Selector Library for Redux > A library for creating memoized selector functions for Redux stores. Reselect computes derived data efficiently, preventing unnecessary re-renders and keeping component logic clean. ## Install Save in your project root: # Reselect — Memoized Selector Library for Redux ## Quick Use ```bash npm install reselect ``` ```js import { createSelector } from "reselect"; const selectTodos = state => state.todos; const selectDone = createSelector(selectTodos, todos => todos.filter(t => t.done)); ``` ## Introduction Reselect is the official selector library for Redux that creates memoized, composable selector functions. It prevents expensive recomputation by caching results and only recalculating when relevant inputs change, which directly reduces unnecessary React re-renders. ## What Reselect Does - Creates memoized selectors that cache their output based on input equality - Composes selectors from other selectors for clean derived-data pipelines - Integrates seamlessly with Redux and React-Redux via `useSelector` - Supports custom memoization functions and equality checks - Provides `createStructuredSelector` for mapping multiple selectors to props ## Architecture Overview Reselect selectors are pure functions composed in a dependency graph. Each selector receives one or more input selectors and a result function. The library compares current inputs to previous inputs using reference equality by default; if nothing changed, it returns the cached result. This cascading memoization means deep selector chains only recompute the parts whose dependencies actually changed. ## Self-Hosting & Configuration - Install from npm: `npm install reselect` - Import `createSelector` and define input selectors pointing at state slices - Chain selectors by passing one selector's output as another's input - Use `createSelectorCreator` to swap in custom memoization (e.g., deep equality) - Pair with Redux Toolkit's `createSlice` for a modern Redux setup ## Key Features - Default reference-equality memoization with zero config - Composable selector chains for complex derived data - Pluggable memoization via `createSelectorCreator` - TypeScript support with strong type inference - Tiny footprint with no external dependencies ## Comparison with Similar Tools - **Redux Toolkit (createSelector)** — Re-exports Reselect; identical API, bundled with RTK - **Zustand** — Built-in selectors with shallow compare; no separate library needed - **MobX** — Uses reactive computed values instead of manual selectors - **Jotai** — Atom-based derived state; different paradigm from selector composition ## FAQ **Q: Is Reselect still needed with Redux Toolkit?** A: Redux Toolkit includes Reselect as a dependency and re-exports `createSelector`, so you get Reselect automatically when using RTK. **Q: How do I handle selectors that depend on component props?** A: Pass a factory function to `useMemo` that creates a per-instance selector, or use Reselect's `createSelector` with explicit argument selectors. **Q: Can Reselect memoize across multiple arguments?** A: Yes. Each input selector can extract a different argument. The result function receives all extracted values and the output is memoized based on all of them. **Q: Does Reselect work outside Redux?** A: Yes. Reselect is a general-purpose memoized-selector library. It works with any state container or plain objects. ## Sources - [GitHub Repository](https://github.com/reduxjs/reselect) - [Official Documentation](https://reselect.js.org) --- Source: https://tokrepo.com/en/workflows/asset-57ebc89a Author: AI Open Source