Configs2026年7月28日·1 分钟阅读

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.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Reselect
直接安装命令
npx -y tokrepo@latest install 57ebc89a-8aa2-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

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

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产