reduxjs /reselect

Selector library for Redux

★ 18,999⑂ 668👁 158⑃ 369● 424▤ 49
TypeScriptMITCreated 2015-07-01redux.js.org/reselect
下载:v5.3.0v5.3.0 ↓5.3.02026-08-22
+0
日增长
18,999
stars
668
forks
158
watchers
369
prs
424
issues
49
releases

README

Reselect

[![npm package][npm-badge]][npm][![Coveralls][coveralls-badge]][coveralls][![GitHub Workflow Status][build-badge]][build]![TypeScript][typescript-badge]

A library for creating memoized "selector" functions. Commonly used with Redux, but usable with any plain JS immutable data as well.

- Selectors can compute derived data, allowing [Redux] to store the minimal possible state.
- Selectors are efficient. A selector is not recomputed unless one of its arguments changes.
- Selectors are composable. They can be used as input to other selectors.

The Redux docs usage page on Deriving Data with Selectors covers the purpose and motivation for selectors, why memoized selectors are useful, typical Reselect usage patterns, and using selectors with [React-Redux].

 Installation

 Redux Toolkit

While Reselect is not exclusive to [Redux], it is already included by default in the official Redux Toolkit package - no further installation needed.

ts
import { createSelector } from '@reduxjs/toolkit'


 Standalone

For standalone usage, install the reselect package:

bash
 NPM
npm install reselect

 Yarn
yarn add reselect

 pnpm
pnpm add reselect


---

 Documentation

The Reselect docs are available at https://reselect.js.org, and include usage guides and API references:

- Introduction
- How Does Reselect Work?
- API Reference:
  - [createSelector]
  - [createSelectorCreator]
  - [createStructuredSelector]
  - Development-Only Checks
  - [lruMemoize]
  - [weakMapMemoize]
- FAQ

 Basic Usage

Reselect exports a [createSelector] API, which generates memoized selector functions. [createSelector] accepts one or more [input selectors], which extract values from arguments, and a [result function] function that receives the extracted values and should return a derived value. If the generated [output selector] is called multiple times, the output will only be recalculated when the extracted values have changed.

You can play around with the following example in this CodeSandbox:

ts
import { createSelector } from 'reselect'

interface RootState {
  todos: { id: number; completed: boolean }[]
  alerts: { id: number; read: boolean }[]
}

const state: RootState = {
  todos: [
    { id: 0, completed: false },
    { id: 1, completed: true }
  ],
  alerts: [
    { id: 0, read: false },
    { id: 1, read: true }
  ]
}

const selectCompletedTodos = (state: RootState) = {
  console.log('selector ran')
  return state.todos.filter(todo = todo.completed === true)
}

selectCompletedTodos(state) // selector ran
selectCompletedTodos(state) // selector ran
selectCompletedTodos(state) // selector ran

const memoizedSelectCompletedTodos = createSelector(
  [(state: RootState) = state.todos],
  todos = {
    console.log('memoized selector ran')
    return todos.filter(todo = todo.completed === true)
  }
)

memoizedSelectCompletedTodos(state) // memoized selector ran
memoizedSelectCompletedTodos(state)
memoizedSelectCompletedTodos(state)

console.log(selectCompletedTodos(state) 

Top issues

Discussions

Latest release

v5.3.0 v5.3.0 2026-08-22
This feature release adds a maxSize option to weakMapMemoize to bound cache growth, adds a new development-mode check that warns when a selector's cache grows without bound, improves memoization performance, removes the experimental unstable_autotrackMemoize, and updates our TypeScript support matrix and documentation.

 Changelog

 maxSize Option for weakMapMemoize

weakMapMemoize has been the default memoizer since v5.0, and its main benefit is the infinite cache size.  Prior to v5, selector instances had a default cache size of 1, which meant having to create unique selector instances

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON