{"name":"reselect","version":"5.0.0-rc.1","keywords":["react","redux"],"license":"MIT","_id":"reselect@5.0.0-rc.1","maintainers":[{"name":"gaearon","email":"dan.abramov@gmail.com"},{"name":"timdorr","email":"timdorr@timdorr.com"},{"name":"ellbee","email":"l_bannard@yahoo.co.uk"},{"name":"phryneas","email":"mail@lenzw.de"},{"name":"acemarke","email":"mark.erikson@gmail.com"},{"name":"eskimojo","email":"ben.j.durrant@gmail.com"}],"contributors":[{"url":"https://github.com/ellbee","name":"Lee Bannard","email":"l_bannard@yahoo.co.uk"},{"url":"https://github.com/faassen","name":"Martijn Faassen"},{"url":"https://github.com/ianks","name":"Ian Ker-Seymer","email":"i.kerseymer@gmail.com"},{"url":"https://github.com/SpainTrain","name":"Mike S"},{"url":"https://github.com/omnidan","name":"Daniel Bugl","email":"me@omnidan.net"},{"url":"https://github.com/ryanatkn","name":"Ryan"},{"url":"https://github.com/HeyImAlex","name":"Alex Guerra","email":"alex@heyimalex.com"},{"url":"https://github.com/speedskater","name":"speedskater"},{"url":"https://github.com/sericaia","name":"Daniela Borges"},{"url":"https://github.com/existentialism","name":"Brian Ng","email":"bng412@gmail.com"},{"url":"https://github.com/chentsulin","name":"C. T. Lin","email":"chentsulin@gmail.com"},{"url":"https://github.com/chungchiehlun","name":"Jay","email":"wuceh14678@gmail.com"},{"url":"https://github.com/madebyherzblut","name":"Christian Schuhmann"},{"url":"https://github.com/volrath","name":"Daniel Barreto","email":"daniel.barreto.n@gmail.com"},{"url":"https://github.com/ifunk","name":"Adam Royle"},{"url":"https://github.com/elliotcm","name":"Elliot Crosby-McCullough","email":"elliot.cm@gmail.com"},{"url":"https://github.com/frankwallis","name":"frankwallis"},{"url":"https://github.com/kaddopur","name":"Jason Huang","email":"chaoju.huang@gmail.com"},{"url":"https://github.com/joshkel","name":"Josh Kelley"},{"url":"https://github.com/leonaves","name":"Leon Aves"},{"url":"https://github.com/markdalgleish","name":"Mark Dalgleish"},{"url":"https://github.com/chromakode","name":"Max Goodman","email":"c@chromako.de"},{"url":"https://github.com/weblancaster","name":"Michael Lancaster","email":"michaell.llancaster@gmail.com"},{"url":"https://github.com/zalmoxisus","name":"Mihail Diordiev"},{"url":"https://github.com/PSpSynedra","name":"PSpSynedra"},{"url":"https://github.com/SimenB","name":"Simen Bekkhus","email":"sbekkhus91@gmail.com"},{"url":"https://github.com/WadePeterson","name":"Wade Peterson"},{"url":"https://github.com/ambar","name":"长天之云","email":"ambar.lee@gmail.com"},{"url":"https://github.com/courthead","name":"Courtland Allen","email":"csallen@alum.mit.edu"},{"url":"https://github.com/HenrikJoreteg","name":"Henrik Joreteg","email":"henrik@joreteg.com"},{"url":"https://github.com/kyldvs","name":"Kyle Davis"},{"url":"https://github.com/clickclickonsal","name":"Salvador Hernandez","email":"s.hernandez5400@gmail.com"},{"url":"https://github.com/npbee","name":"Nick Ball"},{"url":"https://github.com/mctep","name":"mctep"},{"url":"https://github.com/jacobrask","name":"Jacob Rask","email":"jacob@jacobrask.net"},{"url":"https://github.com/luqmaan","name":"Luqmaan Dawoodjee","email":"ldawoodjee@gmail.com"},{"url":"https://github.com/wbreakell","name":"Walter Breakell"},{"url":"https://github.com/matthetherington","name":"Matthew Hetherington"},{"url":"https://github.com/mjw56","name":"Mike Wilcox","email":"mwilcox56@gmail.com"},{"url":"https://github.com/threehams","name":"David Edmondson"},{"url":"https://github.com/zandroid","name":"Andrey Zaytsev","email":"za@zalab.net"},{"url":"https://github.com/1ven","name":"1ven"},{"url":"https://github.com/alexesdev","name":"Alexey Yurchenko","email":"alexes.dev@gmail.com"},{"url":"https://github.com/dpwrussell","name":"Douglas Russell"},{"url":"https://github.com/yoni-tock","name":"Yonatan Kogan"},{"url":"https://github.com/pesho","name":"Peter Petrov"},{"url":"https://github.com/wbreakell","name":"Walter Breakell"},{"url":"https://github.com/madeinfree","name":"Whien","email":"sal95610@gmail.com"},{"url":"https://github.com/bsideup","name":"Sergei Egorov","email":"bsideup@gmail.com"},{"url":"https://github.com/jimbolla","name":"Jim Bolla"},{"url":"https://github.com/carlbernrdo","name":"Carl Bernardo"},{"url":"https://github.com/aikoven","name":"Daniel Lytkin","email":"dan.lytkin@gmail.com"},{"url":"https://github.com/johnhaley81","name":"John Haley","email":"john@haley.io"},{"url":"https://github.com/alex3165","name":"Alexandre","email":"alexr.3165@gmail.com"}],"homepage":"https://github.com/reduxjs/reselect#readme","bugs":{"url":"https://github.com/reduxjs/reselect/issues"},"dist":{"shasum":"931940d65793bef62850961cc4135b718062dc8e","tarball":"http://registry-npm.ywwl.com/reselect/download/reselect-5.0.0-rc.1.tgz","fileCount":29,"integrity":"sha512-wj5aaS7l7IQRctxKcElF9ODmnl3qm2HLmes7UFam9pKxB/AsyDjWyRkTnExFrmjrS18mvXz1Gz/enqEPZcFs1w==","signatures":[{"sig":"MEYCIQDDNlJ60WeudBGS77dDZjF0uYStQJQZnx4gHvtWSWp3ZgIhAOkVkhXm1wqi1dzTHwItxv2agRDgLgKmWEraAZwQqrde","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":654689,"size":140340,"noattachment":false,"key":"/reselect/-/reselect-5.0.0-rc.1.tgz"},"main":"./dist/cjs/reselect.cjs","types":"./dist/reselect.d.ts","module":"./dist/reselect.legacy-esm.js","readme":"# Reselect\r\n\r\n[![npm package][npm-badge]][npm][![Coveralls][coveralls-badge]][coveralls][![GitHub Workflow Status][build-badge]][build]![TypeScript][typescript-badge]\r\n\r\nA library for creating memoized \"selector\" functions. Commonly used with Redux, but usable with any plain JS immutable data as well.\r\n\r\n- Selectors can compute derived data, allowing [Redux] to store the minimal possible state.\r\n- Selectors are efficient. A selector is not recomputed unless one of its arguments changes.\r\n- Selectors are composable. They can be used as input to other selectors.\r\n\r\nThe **Redux docs usage page on [Deriving Data with Selectors](https://redux.js.org/usage/deriving-data-selectors)** covers the purpose and motivation for selectors, why memoized selectors are useful, typical Reselect usage patterns, and using selectors with [React-Redux].\r\n\r\n## Installation\r\n\r\n### Redux Toolkit\r\n\r\nWhile Reselect is not exclusive to [Redux], it is already included by default in [the official Redux Toolkit package](https://redux-toolkit.js.org) - no further installation needed.\r\n\r\n```ts\r\nimport { createSelector } from '@reduxjs/toolkit'\r\n```\r\n\r\n### Standalone\r\n\r\nFor standalone usage, install the `reselect` package:\r\n\r\n```bash\r\n# NPM\r\nnpm install reselect\r\n\r\n# Yarn\r\nyarn add reselect\r\n\r\n# Bun\r\nbun add reselect\r\n\r\n# PNPM\r\npnpm add reselect\r\n```\r\n\r\n---\r\n\r\n## Basic Usage\r\n\r\nReselect 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.\r\n\r\nYou can play around with the following **example** in [this CodeSandbox](https://codesandbox.io/s/reselect-example-g3k9gf?file=/src/index.js):\r\n\r\n```ts\r\nimport { createSelector } from 'reselect'\r\n\r\ninterface RootState {\r\n  todos: { id: number; completed: boolean }[]\r\n  alerts: { id: number; read: boolean }[]\r\n}\r\n\r\nconst state: RootState = {\r\n  todos: [\r\n    { id: 0, completed: false },\r\n    { id: 1, completed: true }\r\n  ],\r\n  alerts: [\r\n    { id: 0, read: false },\r\n    { id: 1, read: true }\r\n  ]\r\n}\r\n\r\nconst selectCompletedTodos = (state: RootState) => {\r\n  console.log('selector ran')\r\n  return state.todos.filter(todo => todo.completed === true)\r\n}\r\n\r\nselectCompletedTodos(state) // selector ran\r\nselectCompletedTodos(state) // selector ran\r\nselectCompletedTodos(state) // selector ran\r\n\r\nconst memoizedSelectCompletedTodos = createSelector(\r\n  [(state: RootState) => state.todos],\r\n  todos => {\r\n    console.log('memoized selector ran')\r\n    return todos.filter(todo => todo.completed === true)\r\n  }\r\n)\r\n\r\nmemoizedSelectCompletedTodos(state) // memoized selector ran\r\nmemoizedSelectCompletedTodos(state)\r\nmemoizedSelectCompletedTodos(state)\r\n\r\nconsole.log(selectCompletedTodos(state) === selectCompletedTodos(state)) //=> false\r\n\r\nconsole.log(\r\n  memoizedSelectCompletedTodos(state) === memoizedSelectCompletedTodos(state)\r\n) //=> true\r\n```\r\n\r\nAs you can see from the example above, `memoizedSelectCompletedTodos` does not run the second or third time, but we still get the same return value as last time.\r\n\r\nIn addition to skipping unnecessary recalculations, `memoizedSelectCompletedTodos` returns the existing result reference if there is no recalculation. This is important for libraries like [React-Redux] or [React] that often rely on reference equality checks to optimize UI updates.\r\n\r\n---\r\n\r\n## Table of Contents\r\n\r\n- [Installation](#installation)\r\n  - [Redux Toolkit](#redux-toolkit)\r\n  - [Standalone](#standalone)\r\n- [Basic Usage](#basic-usage)\r\n- [Terminology](#terminology)\r\n- [How Does Reselect Work?](#how-does-reselect-work)\r\n  - [Cascading Memoization](#cascading-memoization)\r\n  - [Why Reselect Is Often Used With Redux](#why-reselect-is-often-used-with-redux)\r\n- [API](#api)\r\n  - [**`createSelector`**][`createSelector`]\r\n  - [**`createSelectorCreator`**][`createSelectorCreator`]\r\n  - [**`createStructuredSelector`**][`createStructuredSelector`]\r\n  - [**`lruMemoize`**][`lruMemoize`]\r\n  - [**`weakMapMemoize`**][`weakMapMemoize`]\r\n  - [**`unstable_autotrackMemoize`**][`unstable_autotrackMemoize`]\r\n- [Debugging Tools](#debuggingtools)\r\n  - [Development-Only Stability Checks](#development-only-stability-checks)\r\n  - [Output Selector Fields](#output-selector-fields)\r\n- [What's New in 5.0.0?](#v5summary)\r\n- [Optimizing Reselect](#optimizing-reselect)\r\n- [FAQ](#faq)\r\n  - [Why isn’t my selector recomputing when the input state changes?](#why-isnt-my-selector-recomputing-when-the-input-state-changes)\r\n  - [Why is my selector recomputing when the input state stays the same?](#why-is-my-selector-recomputing-when-the-input-state-stays-the-same)\r\n  - [Can I use Reselect without Redux?](#can-i-use-reselect-without-redux)\r\n  - [How do I create a selector that takes an argument?](#how-do-i-create-a-selector-that-takes-an-argument)\r\n  - [Can the memoization behavior be customized?](#can-the-memoization-behavior-be-customized)\r\n  - [How do I test a selector?](#how-do-i-test-a-selector)\r\n  - [Can I share a selector across multiple component instances?](#can-i-share-a-selector-across-multiple-component-instances)\r\n  - [Are there TypeScript Typings?](#are-there-typescript-typings)\r\n  - [I am seeing a TypeScript error: `Type instantiation is excessively deep and possibly infinite`](#i-am-seeing-a-typescript-error-type-instantiation-is-excessively-deep-and-possibly-infinite)\r\n  - [How can I make a curried selector?](#how-can-i-make-a-curried-selector)\r\n  - [How can I make pre-typed version of `createSelector` for my root state?](#how-can-i-make-pre-typed-version-of-createselector-for-my-root-state)\r\n  - [What if I want to use `createSelector` without memoization?](#what-if-i-want-to-use-createselector-without-memoization)\r\n- [External References](#external-references)\r\n- [Related Projects](#related-projects)\r\n- [License](#license)\r\n- [Prior Art and Inspiration](#prior-art-and-inspiration)\r\n\r\n---\r\n\r\n## Terminology\r\n\r\n- <a name=\"selector-function\"></a>[**Selector Function**](#selector-function): A function that accepts one or more JavaScript values as arguments, and derives a result. When used with [Redux], the first argument is typically the entire Redux store state.\r\n- <a name=\"input-selectors\"></a>[**input selectors**](#input-selectors): Basic selector functions used as building blocks for creating a memoized selector. They are passed as the first argument(s) to [`createSelector`], and are called with all selector arguments. They are responsible for extracting and providing necessary values to the [result function].\r\n- <a name=\"output-selector\"></a>[**Output Selector**](#output-selector): The actual memoized selectors created by [`createSelector`].\r\n- <a name=\"result-function\"></a>[**Result Function**](#result-function): The function that comes after the [input selectors]. It takes the [input selectors]' return values as arguments and returns a result.\r\n- <a name=\"dependencies\"></a>[**`Dependencies`**](#dependencies): Same as [input selectors]. They are what the [output selector] \"depends\" on.\r\n\r\nThe below example serves as a visual aid:\r\n\r\n```ts\r\nconst outputSelector = createSelector(\r\n  [inputSelector1, inputSelector2, inputSelector3], // synonymous with `dependencies`.\r\n  resultFunc // Result function\r\n)\r\n```\r\n\r\n<div align=\"right\">[ <a href=\"#table-of-contents\">↑ Back to top ↑</a> ]</div>\r\n\r\n---\r\n\r\n## How Does Reselect Work?\r\n\r\nReselect, at its core, is a library for creating memoized selectors in JavaScript applications. Its primary role is to efficiently compute derived data based on provided inputs. A key aspect of Reselect's internal mechanism is how it orchestrates the flow of arguments from the final selector to its constituent [input selectors].\r\n\r\n```ts\r\nconst finalSelector = (...args) => {\r\n  const extractedValues = inputSelectors.map(inputSelector =>\r\n    inputSelector(...args)\r\n  )\r\n  return resultFunc(...extractedValues)\r\n}\r\n```\r\n\r\nIn this pattern, the `finalSelector` is composed of several [input selectors], **all receiving the same arguments as the final selector**. Each input selector processes its part of the data, and the results are then combined and further processed by the [result function]. Understanding this argument flow is crucial for appreciating how Reselect optimizes data computation and minimizes unnecessary recalculations.\r\n\r\n<a id=\"cascadingmemoization\"></a>\r\n\r\n### Cascading Memoization\r\n\r\nReselect uses a two-stage \"cascading\" approach to memoizing functions:\r\n\r\n<details><summary><b>Detailed Explanation: Cascading Memoization</b></summary>\r\n\r\nThe way Reselect works can be broken down into multiple parts:\r\n\r\n1. **Initial Run**: On the first call, Reselect runs all the [input selectors], gathers their results, and passes them to the [result function].\r\n\r\n2. **Subsequent Runs**: For subsequent calls, Reselect performs two levels of checks:\r\n\r\n   - **First Level**: It compares the current arguments with the previous ones (done by `argsMemoize`).\r\n\r\n     - If they're the same, it returns the cached result without running the [input selectors] or the [result function].\r\n\r\n     - If they differ, it proceeds (\"cascades\") to the second level.\r\n\r\n   - **Second Level**: It runs the [input selectors] and compares their current results with the previous ones (done by `memoize`).\r\n     > [!NOTE]\r\n     > If any one of the [input selectors] return a different result, all [input selectors] will recalculate.\r\n     - If the results are the same, it returns the cached result without running the [result function].\r\n     - If the results differ, it runs the [result function].\r\n\r\nThis behavior is what we call **_Cascading Double-Layer Memoization_**.\r\n\r\n#### Reselect Vs Standard Memoization\r\n\r\n##### Standard Memoization\r\n\r\n![normal-memoization-function](docs/assets//normal-memoization-function.png)\r\n\r\n_Standard memoization only compares arguments. If they're the same, it returns the cached result._\r\n\r\n##### Memoization with Reselect\r\n\r\n![reselect-memoization](docs/assets//reselect-memoization.png)\r\n\r\n_Reselect adds a second layer of checks with the [input selectors]. This is crucial in [Redux] applications where state references change frequently._\r\n\r\nA normal [memoization] function will compare the arguments, and if they are the same as last time, it will skip running the function and return the cached result. However, Reselect enhances this by introducing a second tier of checks via its [input selectors]. It's possible that the arguments passed to these [input selectors] may change, yet their results remain the same. When this occurs, Reselect avoids re-executing the [result function], and returns the cached result.\r\n\r\nThis feature becomes crucial in [Redux] applications, where the `state` changes its reference anytime an `action` is dispatched.\r\n\r\n> [!NOTE]\r\n> The [input selectors] take the same arguments as the [output selector].\r\n\r\n</details>\r\n\r\n### Why Reselect Is Often Used With [Redux]\r\n\r\nWhile Reselect can be used independently from Redux, it is a standard tool used in most Redux applications to help optimize calculations and UI updates:\r\n\r\n<details><summary><b>Detailed Explanation: Reselect and Redux Optimization</b></summary>\r\n\r\nImagine you have a selector like this:\r\n\r\n```ts\r\nconst selectCompletedTodos = (state: RootState) =>\r\n  state.todos.filter(todo => todo.completed === true)\r\n```\r\n\r\nSo you decide to memoize it:\r\n\r\n```ts\r\nconst selectCompletedTodos = someMemoizeFunction((state: RootState) =>\r\n  state.todos.filter(todo => todo.completed === true)\r\n)\r\n```\r\n\r\nThen you update `state.alerts`:\r\n\r\n```ts\r\nstore.dispatch(toggleRead(0))\r\n```\r\n\r\nNow when you call `selectCompletedTodos`, it re-runs, because we have effectively broken memoization.\r\n\r\n```ts\r\nselectCompletedTodos(store.getState())\r\n// Will not run, and the cached result will be returned.\r\nselectCompletedTodos(store.getState())\r\nstore.dispatch(toggleRead(0))\r\n// It recalculates.\r\nselectCompletedTodos(store.getState())\r\n```\r\n\r\nBut why? `selectCompletedTodos` only needs to access `state.todos`, and has nothing to do with `state.alerts`, so why have we broken memoization? Well that's because in [Redux] anytime you make a change to the root `state`, it gets shallowly updated, which means its reference changes, therefore a normal memoization function will always fail the comparison check on the arguments.\r\n\r\nBut with Reselect, we can do something like this:\r\n\r\n```ts\r\nconst selectCompletedTodos = createSelector(\r\n  [(state: RootState) => state.todos],\r\n  todos => todos.filter(todo => todo.completed === true)\r\n)\r\n```\r\n\r\nAnd now we have achieved memoization:\r\n\r\n```ts\r\nselectCompletedTodos(store.getState())\r\n// Will not run, and the cached result will be returned.\r\nselectCompletedTodos(store.getState())\r\nstore.dispatch(toggleRead(0))\r\n// The `input selectors` will run, but the `result function` is\r\n// skipped and the cached result will be returned.\r\nselectCompletedTodos(store.getState())\r\n```\r\n\r\nEven when the overall `state` changes, Reselect ensures efficient memoization through its unique approach. The [result function] doesn't re-run if the relevant part of the `state` (in this case `state.todos`), remains unchanged. This is due to Reselect's [**_Cascading Double-Layer Memoization_**][**_Cascading Memoization_**]. The first layer checks the entire `state`, and the second layer checks the results of the [input selectors]. If the first layer fails (due to a change in the overall `state`) but the second layer succeeds (because `state.todos` is unchanged), Reselect skips recalculating the [result function]. This dual-check mechanism makes Reselect particularly effective in [Redux] applications, ensuring computations are only done when truly necessary.\r\n\r\n</details>\r\n\r\n<div align=\"right\">[ <a href=\"#table-of-contents\">↑ Back to top ↑</a> ]</div>\r\n\r\n---\r\n\r\n## API\r\n\r\n<a id=\"createselector\"></a>\r\n\r\n### createSelector(...inputSelectors | [inputSelectors], resultFunc, createSelectorOptions?)\r\n\r\n<b>Description</b>\r\n\r\nAccepts one or more \"[input selectors]\" (either as separate arguments or a single array),\r\na single \"[result function]\", and an optional options object, and\r\ngenerates a memoized selector function.\r\n\r\n<b>Parameters</b>\r\n\r\n| Name                     | Description                                                                       |\r\n| :----------------------- | :-------------------------------------------------------------------------------- |\r\n| `inputSelectors`         | An array of [input selectors], can also be passed as separate arguments.          |\r\n| `resultFunc`             | A function that takes the results of the [input selectors] as separate arguments. |\r\n| `createSelectorOptions?` | An optional options object that allows for further customization per selector.    |\r\n\r\n<b>Returns</b>\r\n\r\nA memoized [output selector].\r\n\r\n<details><summary><b>Type Parameters</b></summary>\r\n\r\n| Name                          | Description                                                                                                                                                                                            |\r\n| :---------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\r\n| `InputSelectors`              | The type of the [input selectors] array.                                                                                                                                                               |\r\n| `Result`                      | The return type of the [result function] as well as the [output selector].                                                                                                                             |\r\n| `OverrideMemoizeFunction`     | The type of the optional `memoize` function that could be passed into the options object to override the original `memoize` function that was initially passed into [`createSelectorCreator`].         |\r\n| `OverrideArgsMemoizeFunction` | The type of the optional `argsMemoize` function that could be passed into the options object to override the original `argsMemoize` function that was initially passed into [`createSelectorCreator`]. |\r\n\r\n</details>\r\n\r\n<div align=\"right\">[ <a href=\"#table-of-contents\">↑ Back to top ↑</a> ]</div>\r\n\r\n---\r\n\r\n<a id=\"createselectorcreator\" ></a>\r\n\r\n### createSelectorCreator(memoize | options, ...memoizeOptions)\r\n\r\n<b>Description</b>\r\n\r\nAccepts either a `memoize` function and `...memoizeOptions` rest parameter, or since 5.0.0 an `options` object containing a `memoize` function and creates a custom selector creator function.\r\n\r\n<b>Parameters (since 5.0.0)</b>\r\n\r\n| Name                           | Description                                                                                                                                                                                                                                                                                                         |\r\n| :----------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\r\n| `options`                      | An options object containing the `memoize` function responsible for memoizing the `resultFunc` inside [`createSelector`] (e.g., `lruMemoize` or `weakMapMemoize`). It also provides additional options for customizing memoization. While the `memoize` property is mandatory, the rest are optional.           |\r\n| `options.argsMemoize?`         | The optional memoize function that is used to memoize the arguments passed into the [output selector] generated by [`createSelector`] (e.g., `lruMemoize` or `weakMapMemoize`). <br /> **`Default`** `weakMapMemoize`                                                                                           |\r\n| `options.argsMemoizeOptions?`  | Optional configuration options for the `argsMemoize` function. These options are passed to the `argsMemoize` function as the second argument. <br /> since 5.0.0                                                                                                                                                    |\r\n| `options.devModeChecks?` | Overrides the settings for the global development mode checks for the selector. <br /> since 5.0.0 |\r\n| `options.memoize`              | The memoize function that is used to memoize the `resultFunc` inside [`createSelector`] (e.g., `lruMemoize` or `weakMapMemoize`). since 5.0.0                                                                                                                                                                   |\r\n| `options.memoizeOptions?`      | Optional configuration options for the `memoize` function. These options are passed to the `memoize` function as the second argument. <br /> since 5.0.0                                                                                                                                                            |\r\n\r\n<b>Parameters</b>\r\n\r\n| Name                        | Description                                                                                                                                        |\r\n| :-------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------- |\r\n| `memoize`                   | The `memoize` function responsible for memoizing the `resultFunc` inside [`createSelector`] (e.g., `lruMemoize` or `weakMapMemoize`).              |\r\n| `...memoizeOptionsFromArgs` | Optional configuration options for the memoization function. These options are then passed to the memoize function as the second argument onwards. |\r\n\r\n<b>Returns</b>\r\n\r\nA customized [`createSelector`] function.\r\n\r\n<details><summary><b>Type Parameters</b></summary>\r\n\r\n| Name                  | Description                                                                                                                                                                                                                                                |\r\n| :-------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\r\n| `MemoizeFunction`     | The type of the memoize function that is used to memoize the `resultFunc` inside [`createSelector`] (e.g., `lruMemoize` or `weakMapMemoize`).                                                                                                              |\r\n| `ArgsMemoizeFunction` | The type of the optional memoize function that is used to memoize the arguments passed into the [output selector] generated by [`createSelector`] (e.g., `lruMemoize` or `weakMapMemoize`). If none is explicitly provided, `weakMapMemoize` will be used. |\r\n\r\n</details>\r\n\r\n<details><summary><b>Examples</b></summary>\r\n\r\n##### Using `options` (since 5.0.0)\r\n\r\n```ts\r\nconst customCreateSelector = createSelectorCreator({\r\n  memoize: customMemoize, // Function to be used to memoize `resultFunc`\r\n  memoizeOptions: [memoizeOption1, memoizeOption2], // Options passed to `customMemoize` as the second argument onwards\r\n  argsMemoize: customArgsMemoize, // Function to be used to memoize the selector's arguments\r\n  argsMemoizeOptions: [argsMemoizeOption1, argsMemoizeOption2] // Options passed to `customArgsMemoize` as the second argument onwards\r\n})\r\n\r\nconst customSelector = customCreateSelector(\r\n  [inputSelector1, inputSelector2],\r\n  resultFunc // `resultFunc` will be passed as the first argument to `customMemoize`\r\n)\r\n\r\ncustomSelector(\r\n  ...selectorArgs // Will be memoized by `customArgsMemoize`\r\n)\r\n```\r\n\r\n<div align=\"right\">[ <a href=\"#table-of-contents\">↑ Back to top ↑</a> ]</div>\r\n\r\n---\r\n\r\n##### Using `memoize` and `...memoizeOptions`\r\n\r\n`createSelectorCreator` can be used to make a customized version of [`createSelector`].\r\n\r\nThe `memoize` argument is a memoization function to replace `weakMapMemoize`.\r\n\r\nThe `...memoizeOptions` rest parameters are zero or more configuration options to be passed to `memoizeFunc`. The selectors `resultFunc` is passed as the first argument to `memoize` and the `memoizeOptions` are passed as the second argument onwards:\r\n\r\n```ts\r\nconst customSelectorCreator = createSelectorCreator(\r\n  customMemoize, // Function to be used to memoize `resultFunc`\r\n  option1, // `option1` will be passed as second argument to `customMemoize`\r\n  option2, // `option2` will be passed as third argument to `customMemoize`\r\n  option3 // `option3` will be passed as fourth argument to `customMemoize`\r\n)\r\n\r\nconst customSelector = customSelectorCreator(\r\n  [inputSelector1, inputSelector2],\r\n  resultFunc // `resultFunc` will be passed as first argument to `customMemoize`\r\n)\r\n```\r\n\r\nInternally `customSelector` calls the memoize function as follows:\r\n\r\n```ts\r\ncustomMemoize(resultFunc, option1, option2, option3)\r\n```\r\n\r\n##### Additional Examples\r\n\r\n###### Customize `equalityCheck` for `lruMemoize`\r\n\r\n```js\r\nimport { createSelectorCreator, lruMemoize } from 'reselect'\r\nimport isEqual from 'lodash.isequal'\r\n\r\n// create a \"selector creator\" that uses lodash.isequal instead of ===\r\nconst createDeepEqualSelector = createSelectorCreator(lruMemoize, isEqual)\r\n\r\n// use the new \"selector creator\" to create a selector\r\nconst selectSum = createDeepEqualSelector(\r\n  [state => state.values.filter(val => val < 5)],\r\n  values => values.reduce((acc, val) => acc + val, 0)\r\n)\r\n```\r\n\r\n###### Use memoize function from Lodash for an unbounded cache\r\n\r\n```js\r\nimport { createSelectorCreator } from 'reselect'\r\nimport memoize from 'lodash.memoize'\r\n\r\nconst hashFn = (...args) =>\r\n  args.reduce((acc, val) => acc + '-' + JSON.stringify(val), '')\r\n\r\nconst customSelectorCreator = createSelectorCreator(memoize, hashFn)\r\n\r\nconst selector = customSelectorCreator(\r\n  [state => state.a, state => state.b],\r\n  (a, b) => a + b\r\n)\r\n```\r\n\r\n</details>\r\n\r\n<div align=\"right\">[ <a href=\"#table-of-contents\">↑ Back to top ↑</a> ]</div>\r\n\r\n---\r\n\r\n<a id=\"createstructuredselector\"></a>\r\n\r\n### createStructuredSelector({ inputSelectorsObject }, selectorCreator = createSelector)\r\n\r\n<b>Description</b>\r\n\r\nA convenience function that simplifies returning an object made up of selector results.\r\n\r\n<b>Parameters</b>\r\n\r\n| Name                   | Description                                                            |\r\n| :--------------------- | :--------------------------------------------------------------------- |\r\n| `inputSelectorsObject` | A key value pair consisting of input selectors.                        |\r\n| `selectorCreator?`     | A custom selector creator function. It defaults to [`createSelector`]. |\r\n\r\n<b>Returns</b>\r\n\r\nA memoized structured selector.\r\n\r\n<details><summary><b>Type Parameters</b></summary>\r\n\r\n| Name                   | Description                                                                                                                                                   |\r\n| :--------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------ |\r\n| `InputSelectorsObject` | The shape of the [input selectors] object.                                                                                                                    |\r\n| `MemoizeFunction`      | The type of the memoize function that is used to create the structured selector. It defaults to `weakMapMemoize`.                                             |\r\n| `ArgsMemoizeFunction`  | The type of the of the memoize function that is used to memoize the arguments passed into the generated structured selector. It defaults to `weakMapMemoize`. |\r\n\r\n</details>\r\n\r\n<details><summary><b>Examples</b></summary>\r\n\r\n##### Modern Use Case\r\n\r\n```ts\r\nimport { createSelector, createStructuredSelector } from 'reselect'\r\n\r\ninterface RootState {\r\n  todos: {\r\n    id: number\r\n    completed: boolean\r\n    title: string\r\n    description: string\r\n  }[]\r\n  alerts: { id: number; read: boolean }[]\r\n}\r\n\r\n// This:\r\nconst structuredSelector = createStructuredSelector(\r\n  {\r\n    todos: (state: RootState) => state.todos,\r\n    alerts: (state: RootState) => state.alerts,\r\n    todoById: (state: RootState, id: number) => state.todos[id]\r\n  },\r\n  createSelector\r\n)\r\n\r\n// Is essentially the same as this:\r\nconst selector = createSelector(\r\n  [\r\n    (state: RootState) => state.todos,\r\n    (state: RootState) => state.alerts,\r\n    (state: RootState, id: number) => state.todos[id]\r\n  ],\r\n  (todos, alerts, todoById) => {\r\n    return {\r\n      todos,\r\n      alerts,\r\n      todoById\r\n    }\r\n  }\r\n)\r\n```\r\n\r\nIn your component:\r\n\r\n```tsx\r\ninterface Props {\r\n  id: number\r\n}\r\n\r\nconst MyComponent: FC<Props> = ({ id }) => {\r\n  const { todos, alerts, todoById } = useSelector(state =>\r\n    structuredSelector(state, id)\r\n  )\r\n\r\n  return (\r\n    <div>\r\n      Next to do is:\r\n      <h2>{todoById.title}</h2>\r\n      <p>Description: {todoById.description}</p>\r\n      <ul>\r\n        <h3>All other to dos:</h3>\r\n        {todos.map(todo => (\r\n          <li key={todo.id}>{todo.title}</li>\r\n        ))}\r\n      </ul>\r\n    </div>\r\n  )\r\n}\r\n```\r\n\r\n##### Simple Use Case\r\n\r\n```ts\r\nconst selectA = state => state.a\r\nconst selectB = state => state.b\r\n\r\n// The result function in the following selector\r\n// is simply building an object from the input selectors\r\nconst structuredSelector = createSelector(selectA, selectB, (a, b) => ({\r\n  a,\r\n  b\r\n}))\r\n\r\nconst result = structuredSelector({ a: 1, b: 2 }) // will produce { x: 1, y: 2 }\r\n```\r\n\r\n`createStructuredSelector` takes an object whose properties are input selectors and returns a structured selector. The structured selector returns an object with the same keys as the `inputSelectorsObject` argument, but with the selectors replaced with their values.\r\n\r\n```ts\r\nconst selectA = state => state.a\r\nconst selectB = state => state.b\r\n\r\nconst structuredSelector = createStructuredSelector({\r\n  x: selectA,\r\n  y: selectB\r\n})\r\n\r\nconst result = structuredSelector({ a: 1, b: 2 }) // will produce { x: 1, y: 2 }\r\n```\r\n\r\nStructured selectors can be nested:\r\n\r\n```ts\r\nconst nestedSelector = createStructuredSelector({\r\n  subA: createStructuredSelector({\r\n    selectorA,\r\n    selectorB\r\n  }),\r\n  subB: createStructuredSelector({\r\n    selectorC,\r\n    selectorD\r\n  })\r\n})\r\n```\r\n\r\n</details>\r\n\r\n<div align=\"right\">[ <a href=\"#table-of-contents\">↑ Back to top ↑</a> ]</div>\r\n\r\n---\r\n\r\n### Memoization Functions\r\n\r\nReselect comes with a selection of memoization functions, each uniquely designed to address different scenarios and performance requirements. By effectively leveraging these functions, you can significantly enhance the efficiency and responsiveness of your applications.\r\n\r\n<a id=\"lrumemoize\"></a>\r\n\r\n#### lruMemoize(func, equalityCheckOrOptions = referenceEqualityCheck)\r\n\r\n<b>Description</b>\r\n\r\nThe standard memoize function used by [`createSelector`].\r\n\r\nIt has a default cache size of 1. This means it always recalculates when the value of an argument changes. However, this can be customized as needed with a specific max cache size (since 4.1.0).\r\n\r\nIt determines if an argument has changed by calling the `equalityCheck` function. As `lruMemoize` is designed to be used with immutable data, the default `equalityCheck` function checks for changes using [reference equality][Reference Equality Check]:\r\n\r\n```ts\r\nconst referenceEqualityCheck = (previousValue: any, currentValue: any) => {\r\n  return previousValue === currentValue\r\n}\r\n```\r\n\r\n<b>Parameters</b>\r\n\r\n| Name                     | Description                                                 |\r\n| :----------------------- | :---------------------------------------------------------- |\r\n| `func`                   | The function to be memoized.                                |\r\n| `equalityCheckOrOptions` | Either an `equality check` function or an `options` object. |\r\n\r\nSince 4.1.0, `lruMemoize` also accepts an options object as its first argument instead of an `equalityCheck` function. The `options` object may contain:\r\n\r\n```ts\r\ntype EqualityFn = (a: any, b: any) => boolean\r\n\r\ninterface LruMemoizeOptions {\r\n  equalityCheck?: EqualityFn\r\n  resultEqualityCheck?: EqualityFn\r\n  maxSize?: number\r\n}\r\n```\r\n\r\n| Name                  | Description                                                                                                                                                                                                                                                                                                                                                                         |\r\n| :-------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\r\n| `equalityCheck`       | Used to compare the individual arguments of the provided calculation function. <br /> **`Default`** = `referenceEqualityCheck`                                                                                                                                                                                                                                                        |\r\n| `resultEqualityCheck` | If provided, used to compare a newly generated output value against previous values in the cache. If a match is found, the old value is returned. This addresses the common <code>todos.map(todo => todo.id)</code> use case, where an update to another field in the original data causes a recalculation due to changed references, but the output is still effectively the same. |\r\n| `maxSize`             | The cache size for the selector. If greater than 1, the selector will use an LRU cache internally. <br /> **`Default`** = 1                                                                                                                                                                                                                                                         |\r\n\r\n> [!WARNING]\r\n> If `resultEqualityCheck` is used inside `argsMemoizeOptions` it has no effect.\r\n\r\n<b>Returns</b>\r\n\r\nA memoized function with a `.clearCache()` method attached.\r\n\r\n<details><summary><b>Type Parameters</b></summary>\r\n\r\n| Name   | Description                                |\r\n| :----- | :----------------------------------------- |\r\n| `Func` | The type of the function that is memoized. |\r\n\r\n</details>\r\n\r\n<details><summary><b>Examples</b></summary>\r\n\r\n###### Using `lruMemoize` with [`createSelector`]\r\n\r\n```ts\r\nimport { shallowEqual } from 'react-redux'\r\nimport { createSelector } from 'reselect'\r\n\r\nconst selectTodoIds = createSelector(\r\n  [(state: RootState) => state.todos],\r\n  todos => todos.map(todo => todo.id),\r\n  {\r\n    memoizeOptions: {\r\n      equalityCheck: shallowEqual,\r\n      resultEqualityCheck: shallowEqual,\r\n      maxSize: 10\r\n    },\r\n    argsMemoizeOptions: {\r\n      equalityCheck: shallowEqual,\r\n      resultEqualityCheck: shallowEqual,\r\n      maxSize: 10\r\n    }\r\n  }\r\n)\r\n```\r\n\r\n###### Using `lruMemoize` with [`createSelectorCreator`]\r\n\r\n```ts\r\nimport { shallowEqual } from 'react-redux'\r\nimport { createSelectorCreator, lruMemoize } from 'reselect'\r\n\r\nconst createSelectorShallowEqual = createSelectorCreator({\r\n  memoize: lruMemoize,\r\n  memoizeOptions: {\r\n    equalityCheck: shallowEqual,\r\n    resultEqualityCheck: shallowEqual,\r\n    maxSize: 10\r\n  },\r\n  argsMemoize: lruMemoize,\r\n  argsMemoizeOptions: {\r\n    equalityCheck: shallowEqual,\r\n    resultEqualityCheck: shallowEqual,\r\n    maxSize: 10\r\n  }\r\n})\r\n\r\nconst selectTodoIds = createSelectorShallowEqual(\r\n  [(state: RootState) => state.todos],\r\n  todos => todos.map(todo => todo.id)\r\n)\r\n```\r\n\r\n</details>\r\n\r\n<div align=\"right\">[ <a href=\"#table-of-contents\">↑ Back to top ↑</a> ]</div>\r\n\r\n---\r\n\r\n<a id=\"weakmapmemoize\"></a>\r\n\r\n#### weakMapMemoize(func) - (since 5.0.0)\r\n\r\n<b>Description</b>\r\n\r\n[`lruMemoize`] has to be explicitly configured to have a cache size larger than 1, and uses an LRU cache internally.\r\n\r\n`weakMapMemoize` creates a tree of [`WeakMap`]-based cache nodes based on the identity of the arguments it's been called with (in this case, the extracted values from your input selectors). **This allows `weakMapMemoize` to have an effectively infinite cache size**. Cache results will be kept in memory as long as references to the arguments still exist, and then cleared out as the arguments are garbage-collected.\r\n\r\n<details><summary><b>Design Tradeoffs</b></summary>\r\n\r\n- Pros:\r\n\r\n  - It has an effectively infinite cache size, but you have no control over\r\n    how long values are kept in cache as it's based on garbage collection and [`WeakMap`]s.\r\n\r\n- Cons:\r\n  - There's currently no way to alter the argument comparisons. They're based on [strict reference equality][Reference Equality Check].\r\n\r\n</details>\r\n\r\n<details><summary><b>Use Cases</b></summary>\r\n\r\n- This memoizer is likely best used for cases where you need to call the\r\n  same selector instance with many different arguments, such as a single\r\n  selector instance that is used in a list item component and called with\r\n  item IDs like:\r\n\r\n```ts\r\nuseSelector(state => selectSomeData(state, id))\r\n```\r\n\r\nPrior to `weakMapMemoize`, you had this problem:\r\n\r\n```ts\r\ninterface RootState {\r\n  items: { id: number; category: string; name: string }[]\r\n}\r\n\r\nconst selectItemsByCategory = createSelector(\r\n  [\r\n    (state: RootState) => state.items,\r\n    (state: RootState, category: string) => category\r\n  ],\r\n  (items, category) => items.filter(item => item.category === category)\r\n)\r\n\r\nselectItemsByCategory(state, 'Electronics') // Selector runs\r\nselectItemsByCategory(state, 'Electronics')\r\nselectItemsByCategory(state, 'Stationery') // Selector runs\r\nselectItemsByCategory(state, 'Electronics') // Selector runs again!\r\n```\r\n\r\nBefore you could solve this in a number of different ways:\r\n\r\n1. Set the `maxSize` with [`lruMemoize`]:\r\n\r\n```ts\r\nconst selectItemsByCategory = createSelector(\r\n  [\r\n    (state: RootState) => state.items,\r\n    (state: RootState, category: string) => category\r\n  ],\r\n  (items, category) => items.filter(item => item.category === category),\r\n  {\r\n    memoizeOptions: {\r\n      maxSize: 10\r\n    }\r\n  }\r\n)\r\n```\r\n\r\nBut this required having to know the cache size ahead of time.\r\n\r\n2. Create unique selector instances using [`useMemo`].\r\n\r\n```tsx\r\nconst makeSelectItemsByCategory = (category: string) =>\r\n  createSelector([(state: RootState) => state.items], items =>\r\n    items.filter(item => item.category === category)\r\n  )\r\n\r\ninterface Props {\r\n  category: string\r\n}\r\n\r\nconst MyComponent: FC<Props> = ({ category }) => {\r\n  const selectItemsByCategory = useMemo(\r\n    () => makeSelectItemsByCategory(category),\r\n    [category]\r\n  )\r\n\r\n  const itemsByCategory = useSelector(selectItemsByCategory)\r\n\r\n  return (\r\n    <div>\r\n      {itemsByCategory.map(item => (\r\n        <div key={item.id}>{item.name}</div>\r\n      ))}\r\n    </div>\r\n  )\r\n}\r\n```\r\n\r\n3. Using [`useCallback`].\r\n\r\n```tsx\r\nconst selectItemsByCategory = createSelector(\r\n  [\r\n    (state: RootState) => state.items,\r\n    (state: RootState, category: string) => category\r\n  ],\r\n  (items, category) => items.filter(item => item.category === category)\r\n)\r\n\r\nconst MyComponent: FC<Props> = ({ category }) => {\r\n  const selectItemsByCategoryMemoized = useCallback(selectItemsByCategory, [])\r\n\r\n  const itemsByCategory = useSelector(state =>\r\n    selectItemsByCategoryMemoized(state, category)\r\n  )\r\n\r\n  return (\r\n    <div>\r\n      {itemsByCategory.map(item => (\r\n        <div key={item.id}>{item.name}</div>\r\n      ))}\r\n    </div>\r\n  )\r\n}\r\n```\r\n\r\n4. Use [`re-reselect`]:\r\n\r\n```ts\r\nimport { createCachedSelector } from 're-reselect'\r\n\r\nconst selectItemsByCategory = createCachedSelector(\r\n  [\r\n    (state: RootState) => state.items,\r\n    (state: RootState, category: string) => category\r\n  ],\r\n  (items, category) => items.filter(item => item.category === category)\r\n)((state: RootState, category: string) => category)\r\n```\r\n\r\nStarting in 5.0.0, you can eliminate this problem using `weakMapMemoize`.\r\n\r\n```ts\r\nconst selectItemsByCategory = createSelector(\r\n  [\r\n    (state: RootState) => state.items,\r\n    (state: RootState, category: string) => category\r\n  ],\r\n  (items, category) => items.filter(item => item.category === category),\r\n  {\r\n    memoize: weakMapMemoize,\r\n    argsMemoize: weakMapMemoize\r\n  }\r\n)\r\n\r\nselectItemsByCategory(state, 'Electronics') // Selector runs\r\nselectItemsByCategory(state, 'Electronics') // Cached\r\nselectItemsByCategory(state, 'Stationery') // Selector runs\r\nselectItemsByCategory(state, 'Electronics') // Still cached!\r\n```\r\n\r\nThis solves the problem of having to know and set the cache size prior to creating a memoized selector. Because `weakMapMemoize` essentially provides a dynamic cache size out of the box.\r\n\r\n</details>\r\n\r\n<b>Parameters</b>\r\n\r\n| Name   | Description                  |\r\n| :----- | :--------------------------- |\r\n| `func` | The function to be memoized. |\r\n\r\n<b>Returns</b>\r\n\r\nA memoized function with a `.clearCache()` method attached.\r\n\r\n<details><summary><b>Type Parameters</b></summary>\r\n\r\n| Name   | Description                                |\r\n| :----- | :----------------------------------------- |\r\n| `Func` | The type of the function that is memoized. |\r\n\r\n</details>\r\n\r\n<details><summary><b>Examples</b></summary>\r\n\r\n###### Using `weakMapMemoize` with [`createSelector`]\r\n\r\n```ts\r\nimport { createSelector, weakMapMemoize } from 'reselect'\r\n\r\nconst selectItemsByCategory = createSelector(\r\n  [\r\n    (state: RootState) => state.items,\r\n    (state: RootState, category: string) => category\r\n  ],\r\n  (items, category) => items.filter(item => item.category === category),\r\n  {\r\n    memoize: weakMapMemoize,\r\n    argsMemoize: weakMapMemoize\r\n  }\r\n)\r\n\r\nselectItemsByCategory(state, 'Electronics') // Selector runs\r\nselectItemsByCategory(state, 'Electronics')\r\nselectItemsByCategory(state, 'Stationery') // Selector runs\r\nselectItemsByCategory(state, 'Electronics')\r\n```\r\n\r\n###### Using `weakMapMemoize` with [`createSelectorCreator`]\r\n\r\n```ts\r\nimport { createSelectorCreator, weakMapMemoize } from 'reselect'\r\n\r\nconst createSelectorWeakMap = createSelectorCreator({\r\n  memoize: weakMapMemoize,\r\n  argsMemoize: weakMapMemoize\r\n})\r\n\r\nconst selectItemsByCategory = createSelectorWeakMap(\r\n  [\r\n    (state: RootState) => state.items,\r\n    (state: RootState, category: string) => category\r\n  ],\r\n  (items, category) => items.filter(item => item.category === category)\r\n)\r\n\r\nselectItemsByCategory(state, 'Electronics') // Selector runs\r\nselectItemsByCategory(state, 'Electronics')\r\nselectItemsByCategory(state, 'Stationery') // Selector runs\r\nselectItemsByCategory(state, 'Electronics')\r\n```\r\n\r\n</details>\r\n\r\n<div align=\"right\">[ <a href=\"#table-of-contents\">↑ Back to top ↑</a> ]</div>\r\n\r\n---\r\n\r\n<a id=\"unstable_autotrackMemoize\"></a>\r\n\r\n#### unstable_autotrackMemoize(func) - (since 5.0.0)\r\n\r\n<b>Description</b>\r\n\r\nUses an \"auto-tracking\" approach inspired by the work of the Ember Glimmer team. It uses a Proxy to wrap arguments and track accesses to nested fields in your selector on first read. Later, when the selector is called with new arguments, it identifies which accessed fields have changed and only recalculates the result if one or more of those accessed fields have changed. This allows it to be more precise than the shallow equality checks in `lruMemoize`.\r\n\r\n> [!WARNING]\r\n> This API is still experimental and undergoing testing.\r\n\r\n<details><summary><b>Design Tradeoffs</b></summary>\r\n\r\n- Pros:\r\n\r\n  - It is likely to avoid excess calculations and recalculate fewer times than `lruMemoize` will, which may also result in fewer component re-renders.\r\n\r\n- Cons:\r\n\r\n  - It only has a cache size of 1.\r\n  - It is slower than `lruMemoize`, because it has to do more work. (How much slower is dependent on the number of accessed fields in a selector, number of calls, frequency of input changes, etc)\r\n  - It can have some unexpected behavior. Because it tracks nested field accesses, cases where you don't access a field will not recalculate properly. For example, a badly-written selector like:\r\n\r\n  ```ts\r\n  createSelector([state => state.todos], todos => todos)\r\n  ```\r\n\r\n  that just immediately returns the extracted value will never update, because it doesn't see any field accesses to check.\r\n\r\n</details>\r\n\r\n<details><summary><b>Use Cases</b></summary>\r\n\r\n- It is likely best used for cases where you need to access specific nested fields in data, and avoid recalculating if other fields in the same data objects are immutably updated.\r\n\r\n</details>\r\n\r\n<b>Parameters</b>\r\n\r\n| Name   | Description                  |\r\n| :----- | :--------------------------- |\r\n| `func` | The function to be memoized. |\r\n\r\n<b>Returns</b>\r\n\r\nA memoized function with a `.clearCache()` method attached.\r\n\r\n<details><summary><b>Type Parameters</b></summary>\r\n\r\n| Name   | Description                                |\r\n| :----- | :----------------------------------------- |\r\n| `Func` | The type of the function that is memoized. |\r\n\r\n</details>\r\n\r\n<details><summary><b>Examples</b></summary>\r\n\r\n###### Using `unstable_autotrackMemoize` with [`createSelector`]\r\n\r\n```ts\r\nimport { unstable_autotrackMemoize, createSelector } from 'reselect'\r\n\r\nconst selectTodoIds = createSelector(\r\n  [(state: RootState) => state.todos],\r\n  todos => todos.map(todo => todo.id),\r\n  { memoize: unstable_autotrackMemoize }\r\n)\r\n```\r\n\r\n###### Using `unstable_autotrackMemoize` with [`createSelectorCreator`]\r\n\r\n```ts\r\nimport { unstable_autotrackMemoize, createSelectorCreator } from 'reselect'\r\n\r\nconst createSelectorAutotrack = createSelectorCreator({\r\n  memoize: unstable_autotrackMemoize\r\n})\r\n\r\nconst selectTodoIds = createSelectorAutotrack(\r\n  [(state: RootState) => state.todos],\r\n  todos => todos.map(todo => todo.id)\r\n)\r\n```\r\n\r\n</details>\r\n\r\n<div align=\"right\">[ <a href=\"#table-of-contents\">↑ Back to top ↑</a> ]</div>\r\n\r\n---\r\n\r\n<a id=\"debuggingtools\"></a>\r\n\r\n## Debugging Tools\r\n\r\n<a id=\"developmentonlychecks\"></a>\r\n\r\n### Development-Only Checks\r\n\r\nReselect includes extra checks in development mode to help catch and warn about mistakes in selector behavior.\r\n\r\n<a id=\"inputstabilitycheck\"></a>\r\n\r\n#### `inputStabilityCheck`\r\n\r\nDue to how [**_Cascading Memoization_**] works in Reselect, it is crucial that your [input selectors] do not return a new reference on each run. If an [input selector][input selectors] always returns a new reference, like\r\n\r\n```ts\r\nstate => ({ a: state.a, b: state.b })\r\n```\r\n\r\nor\r\n\r\n```ts\r\nstate => state.todos.map(todo => todo.id)\r\n```\r\n\r\nthat will cause the selector to never memoize properly.\r\nSince this is a common mistake, we've added a development mode check to catch this. By default, [`createSelector`] will now run the [input selectors] twice during the first call to the selector. If the result appears to be different for the same call, it will log a warning with the arguments and the two different sets of extracted input values.\r\n\r\n```ts\r\ntype DevModeCheckFrequency = 'always' | 'once' | 'never'\r\n```\r\n\r\n| Possible Values | Description                                     |\r\n| :-------------- | :---------------------------------------------- |\r\n| `once`          | Run only the first time the selector is called. |\r\n| `always`        | Run every time the selector is called.          |\r\n| `never`         | Never run the input stability check.            |\r\n\r\n> [!IMPORTANT]\r\n> The input stability check is automatically disabled in production environments.\r\n\r\nYou can configure this behavior in two ways:\r\n\r\n<a id=\"setglobaldevmodechecks\"></a>\r\n\r\n##### 1. Globally through `setGlobalDevModeChecks`:\r\n\r\nA `setGlobalDevModeChecks` function is exported from Reselect, which should be called with the desired setting.\r\n\r\n```ts\r\nimport { setGlobalDevModeChecks } from 'reselect'\r\n\r\n// Run only the first time the selector is called. (default)\r\nsetGlobalDevModeChecks({ inputStabilityCheck: 'once' })\r\n\r\n// Run every time the selector is called.\r\nsetGlobalDevModeChecks({ inputStabilityCheck: 'always' })\r\n\r\n// Never run the input stability check.\r\nsetGlobalDevModeChecks({ inputStabilityCheck: 'never' })\r\n```\r\n\r\n##### 2. Per selector by passing an `inputStabilityCheck` option directly to [`createSelector`]:\r\n\r\n```ts\r\n// Create a selector that double-checks the results of input selectors every time it runs.\r\nconst selectCompletedTodosLength = createSelector(\r\n  [\r\n    // ❌ Incorrect Use Case: This input selector will not be memoized properly since it always returns a new reference.\r\n    (state: RootState) =>\r\n      state.todos.filter(({ completed }) => completed === true)\r\n  ],\r\n  completedTodos => completedTodos.length,\r\n  // Will override the global setting.\r\n  { devModeChecks: { inputStabilityCheck: 'always' } }\r\n)\r\n```\r\n\r\n> [!WARNING]\r\n> This will override the global input stability check set by calling `setGlobalDevModeChecks`.\r\n\r\n<a id=\"identityfunctioncheck\"></a>\r\n\r\n#### `identityFunctionCheck`\r\n\r\nWhen working with Reselect, it's crucial to adhere to a fundamental philosophy regarding the separation of concerns between extraction and transformation logic.\r\n\r\n- **Extraction Logic**: This refers to operations like `state => state.todos`, which should be placed in [input selectors]. Extraction logic is responsible for retrieving or 'selecting' data from a broader state or dataset.\r\n\r\n- **Transformation Logic**: In contrast, transformation logic, such as `todos => todos.map(({ id }) => id)`, belongs in the [result function]. This is where you manipulate, format, or transform the data extracted by the input selectors.\r\n\r\nMost importantly, effective memoization in Reselect hinges on following these guidelines. Memoization, only functions correctly when extraction and transformation logic are properly segregated. By keeping extraction logic in input selectors and transformation logic in the result function, Reselect can efficiently determine when to reuse cached results and when to recompute them. This not only enhances performance but also ensures the consistency and predictability of your selectors.\r\n\r\nFor memoization to work as intended, it's imperative to follow both guidelines. If either is disregarded, memoization will not function properly. Consider the following example for clarity:\r\n\r\n```ts\r\n// ❌ Incorrect Use Case: This will not memoize correctly, and does nothing useful!\r\nconst brokenSelector = createSelector(\r\n  // ✔️ GOOD: Contains extraction logic.\r\n  [(state: RootState) => state.todos],\r\n  // ❌ BAD: Does not contain transformation logic.\r\n  todos => todos\r\n)\r\n```\r\n\r\n```ts\r\ntype DevModeCheckFrequency = 'always' | 'once' | 'never'\r\n```\r\n\r\n| Possible Values | Description                                     |\r\n| :-------------- | :---------------------------------------------- |\r\n| `once`          | Run only the first time the selector is called. |\r\n| `always`        | Run every time the selector is called.          |\r\n| `never`         | Never run the identity function check.          |\r\n\r\n> [!IMPORTANT]\r\n> The identity function check is automatically disabled in production environments.\r\n\r\nYou can configure this behavior in two ways:\r\n\r\n<a id=\"setGlobalDevModeChecks\"></a>\r\n\r\n##### 1. Globally through `setGlobalDevModeChecks`:\r\n\r\n```ts\r\nimport { setGlobalDevModeChecks } from 'reselect'\r\n\r\n// Run only the first time the selector is called. (default)\r\nsetGlobalDevModeChecks({ identityFunctionCheck: 'once' })\r\n\r\n// Run every time the selector is called.\r\nsetGlobalDevModeChecks({ identityFunctionCheck: 'always' })\r\n\r\n// Never run the identity function check.\r\nsetGlobalDevModeChecks({ identityFunctionCheck: 'never' })\r\n```\r\n\r\n##### 2. Per selector by passing an `identityFunctionCheck` option directly to [`createSelector`]:\r\n\r\n```ts\r\n// Create a selector that checks to see if the result function is an identity function.\r\nconst selectTodos = createSelector(\r\n  [(state: RootState) => state.todos],\r\n  // This result function does not contain any transformation logic.\r\n  todos => todos,\r\n  // Will override the global setting.\r\n  { devModeChecks: { identityFunctionCheck: 'always' } }\r\n)\r\n```\r\n\r\n<a id=\"outputselectorfields\"></a>\r\n\r\n### Output Selector Fields\r\n\r\nThe output selectors created by <code>createSelector</code> have several additional properties attached to them:\r\n\r\n| Name                            | Description                                                                                                                                                                                   |\r\n| ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\r\n| `resultFunc`                    | The final function passed to [`createSelector`].                                                                                                                                              |\r\n| `memoizedResultFunc`            | The memoized version of `resultFunc`.                                                                                                                                                         |\r\n| `lastResult`                    | Returns the last result calculated by `memoizedResultFunc`.                                                                                                                                   |\r\n| `dependencies`                  | The array of the input selectors used by [`createSelector`] to compose `resultFunc`.                                                                                                          |\r\n| `recomputations`                | Counts the number of times `memoizedResultFunc` has been recalculated.                                                                                                                        |\r\n| `resetRecomputations`           | Resets the count of `recomputations` count to 0.                                                                                                                                              |\r\n| `dependencyRecomputations`      | Counts the number of times the [input selectors] ([`dependencies`]) have been recalculated. This is distinct from `recomputations`, which tracks the recalculations of the [result function]. |\r\n| `resetDependencyRecomputations` | Resets the `dependencyRecomputations` count to 0.                                                                                                                                             |\r\n| `memoize`                       | Function used to memoize the `resultFunc`.                                                                                                                                                    |\r\n| `argsMemoize`                   | Function used to memoize the arguments passed into the [output selector].                                                                                                                     |\r\n\r\n<div align=\"right\">[ <a href=\"#table-of-contents\">↑ Back to top ↑</a> ]</div>\r\n\r\n---\r\n\r\n<a id=\"v5summary\"></a>\r\n\r\n## What's New in 5.0.0?\r\n\r\nVersion 5.0.0 introduces several new features and improvements:\r\n\r\n- **Customization Enhancements**:\r\n\r\n  - Added the ability to pass an options object to [`createSelectorCreator`], allowing for customized `memoize` and `argsMemoize` functions, alongside their respective options (`memoizeOptions` and `argsMemoizeOptions`).\r\n  - The [`createSelector`] function now supports direct customization of `memoize` and `argsMemoize` within its options object.\r\n\r\n- **Memoization Functions**:\r\n\r\n  - Introduced new experimental memoization functions: `weakMapMemoize` and `unstable_autotrackMemoize`.\r\n  - Incorporated `memoize` and `argsMemoize` into the [output selector fields] for debugging purposes.\r\n\r\n- **TypeScript Support and Performance**:\r\n\r\n  - Discontinued support for TypeScript versions below 4.7, aligning with modern TypeScript features.\r\n  - Significantly improved TypeScript performance for nesting [output selector]s. The nesting limit has increased from approximately 8 to around 30 [output selector]s, greatly reducing the occurrence of the infamous `Type instantiation is excessively deep and possibly infinite` error.\r\n\r\n- **Selector API Enhancements**:\r\n\r\n  - Removed the second overload of `createStructuredSelector` due to its susceptibility to runtime errors.\r\n  - Added the `TypedStructuredSelectorCreator` utility type (_currently a work-in-progress_) to facilitate the creation of a pre-typed version of `createStructuredSelector` for your root state.\r\n\r\n- **Additional Functionalities**:\r\n\r\n  - Added `dependencyRecomputations` and `resetDependencyRecomputations` to the [output selector fields]. These additions provide greater control and insight over [input selectors], complementing the new `argsMemoize` API.\r\n  - Introduced `inputStabilityCheck`, a development tool that runs the [input selectors] twice using the same arguments and triggers a warning If they return differing results for the same call.\r\n  - Introduced `identityFunctionCheck`, a development tool that checks to see if the [result function] returns its own input.\r\n\r\nThese updates aim to enhance flexibility, performance, and developer experience. For detailed usage and examples, refer to the updated documentation sections for each feature.\r\n\r\n- **Breaking Changes**:\r\n\r\n  - Removed `ParametricSelector` and `OutputParametricSelector` types. Their functionalities are now integrated into `Selector` and `OutputSelector` respectively, which inherently support additional parameters.\r\n\r\n<div align=\"right\">[ <a href=\"#table-of-contents\">↑ Back to top ↑</a> ]</div>\r\n\r\n---\r\n\r\n<a id=\"optimizingreselect\"></a>\r\n\r\n## Optimizing Reselect\r\n\r\n### Common Mistakes\r\n\r\n<details><summary><b>Click to expand</b></summary>\r\n\r\nA somewhat common mistake is to write an [input selector][input selectors] that extracts a value or does some derivation, and a [result function] that just returns its result:\r\n\r\n```ts\r\n// ❌ BROKEN: this will not memoize correctly, and does nothing useful!\r\nconst brokenSelector = createSelector(\r\n  [(state: RootState) => state.todos],\r\n  todos => todos\r\n)\r\n```\r\n\r\nAny [result function] that just returns its inputs is incorrect! The [result function] should always have the transformation logic.\r\n\r\nSimilarly:\r\n\r\n```ts\r\n// ❌ BROKEN: this will not memoize correctly!\r\nconst brokenSelector = createSelector(\r\n  [(state: RootState) => state],\r\n  state => state.todos\r\n)\r\n```\r\n\r\n</details>\r\n\r\n### Handling Empty Array Results\r\n\r\n<details><summary><b>Click to expand</b></summary>\r\n\r\nTo reduce recalculations, use a predefined empty array when `array.filter` or similar methods result in an empty array.\r\n\r\nSo you can have a pattern like this:\r\n\r\n```ts\r\ninterface RootState {\r\n  todos: {\r\n    id: number\r\n    title: string\r\n    description: string\r\n    completed: boolean\r\n  }[]\r\n}\r\n\r\nconst EMPTY_ARRAY: [] = []\r\n\r\nconst selectCompletedTodos = createSelector(\r\n  [(state: RootState) => state.todos],\r\n  todos => {\r\n    const completedTodos = todos.filter(todo => todo.completed === true)\r\n    return completedTodos.length === 0 ? EMPTY_ARRAY : completedTodos\r\n  }\r\n)\r\n```\r\n\r\nOr to avoid repetition, you can create a wrapper function and reuse it:\r\n\r\n```ts\r\nconst EMPTY_ARRAY: [] = []\r\n\r\nexport const fallbackToEmptyArray = <T>(array: T[]) => {\r\n  return array.length === 0 ? EMPTY_ARRAY : array\r\n}\r\n\r\nconst selectCompletedTodos = createSelector(\r\n  [(state: RootState) => state.todos],\r\n  todos => {\r\n    return fallbackToEmptyArray(todos.filter(todo => todo.completed === true))\r\n  }\r\n)\r\n```\r\n\r\nThis way if the [result function] returns an empty array twice in a row, your component will not re-render due to a stable empty array reference:\r\n\r\n```ts\r\nconst completedTodos = selectCompletedTodos(store.getState())\r\n\r\nstore.dispatch(addTodo())\r\n\r\nconsole.log(completedTodos === selectCompletedTodos(store.getState())) //=> true\r\n```\r\n\r\n</details>\r\n\r\n### Best Practices\r\n\r\n<details><summary><b>Click to expand</b></summary>\r\n\r\nThere are a few details that will help you skip running as many functions as possible and get the best possible performance out of Reselect:\r\n\r\n- Due to the [**_Cascading Memoization_**] in Reselect, The first layer of checks is upon the arguments that are passed to the [output selector], therefore it's best to maintain the same reference for the arguments as much as possible.\r\n- In [Redux], your state will change reference when updated. But it's best to keep the additional arguments as simple as possible, you can pass in objects or array as long as their reference does not change. Or you can pass in primitives like numbers for ids.\r\n- Keep your [input selectors] as simple as possible. It's best if they mostly consist of field accessors like `state => state.todos` or argument providers like `(state, id) => id`. You should not be doing any sort of calculation inside [input selectors], and you should definitely not be returning an object or array with a new reference each time.\r\n- The [result function] is only re-run as a last resort. So make sure to put any and all calculations inside your [result function]. That way, Reselect will only run those calculations if all other checks fail.\r\n\r\nThis:\r\n\r\n```ts\r\n// ✔️ This is optimal because we have less calculations in input selectors and more in the result function.\r\nconst selectorGood = createSelector(\r\n  [(state: RootState) => state.todos],\r\n  todos => someExpensiveComputation(todos)\r\n)\r\n```\r\n\r\nIs preferable to this:\r\n\r\n```ts\r\n// ❌ This is not optimal!\r\nconst selectorBad = createSelector(\r\n  [(state: RootState) => someExpensiveComputation(state.todos)],\r\n  someOtherCalculation\r\n)\r\n```\r\n\r\n</details>\r\n\r\n<div align=\"right\">[ <a href=\"#table-of-contents\">↑ Back to top ↑</a> ]</div>\r\n\r\n---\r\n\r\n## FAQ\r\n\r\n### Why isn’t my selector recomputing when the input state changes?\r\n\r\nCheck that your memoization function is compatible with your state update function (i.e. the reducer if you are using [Redux]). For example, a selector created with [`createSelector`] will not work with a state update function that mutates an existing object instead of creating a new one each time. [`createSelector`] uses an identity check (`===`) to detect that an input has changed, so mutating an existing object will not trigger the selector to recompute because mutating an object does not change its identity. Note that if you are using [Redux], mutating the state object is [almost certainly a mistake](http://redux.js.org/docs/Troubleshooting.html).\r\n\r\n### Why is my selector recomputing when the input state stays the same?\r\n\r\nTo address unexpected recomputations in your selector, first ensure that `inputStabilityCheck` is set to either `'always'` or `'once'`. This setting aids in debugging by monitoring the stability of your inputs. Additionally, utilize [output selector fields] such as `recomputations`, `resetRecomputations`, `dependencyRecomputations`, and `resetDependencyRecomputations`. These tools help identify the source of the issue.\r\n\r\nKeep an eye on the `dependencyRecomputations` count. If it increases while `recomputations` remains the same, it suggests that your arguments are changing references but your [input selectors] are stable which is typically the desired behavior.\r\n\r\n<details><summary><b>Detailed Explanation: Selector Recomputations</b></summary>\r\n\r\nTo delve deeper, you can determine which arguments are changing references too frequently by using the `argsMemoizeOptions` and `equalityCheck`. Consider the following example:\r\n\r\n```ts\r\ninterface RootState {\r\n  todos: { id: number; completed: boolean }[]\r\n  alerts: { id: number; read: boolean; type: string }[]\r\n}\r\n\r\nconst selectAlertsByType = createSelector(\r\n  [\r\n    (state: RootState) => state.alerts,\r\n    (state: RootState, type: string) => type\r\n  ],\r\n  (alerts, type) => alerts.filter(todo => todo.type === type),\r\n  {\r\n    argsMemoizeOptions: {\r\n      // This will check the arguments passed to the output selector.\r\n      equalityCheck: (a, b) => {\r\n        if (a !== b) {\r\n          console.log('Changed argument:', a, 'to', b)\r\n        }\r\n        return a === b\r\n      }\r\n    }\r\n  }\r\n)\r\n```\r\n\r\n</details>\r\n\r\n### Can I use Reselect without [Redux]?\r\n\r\nYes. Reselect has no dependencies on any other package, so although it was designed to be used with [Redux] it can be used independently. It can be used with any plain JS data, such as typical [React] state values, as long as that data is being updated immutably.\r\n\r\n### How do I create a selector that takes an argument?\r\n\r\nEach of the [input selectors] you provide will be called with all of the selector's arguments. You can add additional input selectors to extract arguments and forward them to the [result function], like this:\r\n\r\n```ts\r\nconst selectTodosByCategory = createSelector(\r\n  (state: RootState) => state.todos,\r\n  // Extract the second argument to pass it on\r\n  (state: RootState, category: string) => category,\r\n  (todos, category) => todos.filter(t => t.category === category)\r\n)\r\n```\r\n\r\n<details><summary><b>Detailed Explanation: Selectors and Arguments</b></summary>\r\n\r\nWhen creating a selector that accepts arguments in Reselect, it's important to structure your input and [output selector]s appropriately. Here are key points to consider:\r\n\r\n1. **Consistency in Arguments**: Ensure that all positional arguments across [input selectors] are of the same type for consistency.\r\n\r\n2. **Selective Argument Usage**: Design each selector to use only its relevant argument(s) and ignore the rest. This is crucial because all [input selectors] receive the same arguments that are passed to the [output selector].\r\n\r\nSuppose we have the following state structure:\r\n\r\n```ts\r\ninterface RootState {\r\n  items: {\r\n    id: number\r\n    category: string\r\n    vendor: { id: number; name: string }\r\n  }[]\r\n  // ... other state properties ...\r\n}\r\n```\r\n\r\nTo create a selector that filters `items` based on a `category` and excludes a specific `id`, you can set up your selectors as follows:\r\n\r\n```ts\r\nconst selectAvailableItems = createSelector(\r\n  [\r\n    // First input selector extracts items from the state\r\n    (state: RootState) => state.items,\r\n    // Second input selector forwards the category argument\r\n    (state: RootState, category: string) => category,\r\n    // Third input selector forwards the ID argument\r\n    (state: RootState, category: string, id: number) => id\r\n  ],\r\n  // Output selector uses the extracted items, category, and ID\r\n  (items, category, id) =>\r\n    items.filter(item => item.category === category && item.id !== id)\r\n)\r\n```\r\n\r\nInternally Reselect is doing this:\r\n\r\n```ts\r\n// Input selector #1\r\nconst items = (state: RootState, category: string, id: number) => state.items\r\n// Input selector #2\r\nconst category = (state: RootState, category: string, id: number) => category\r\n// Input selector #3\r\nconst id = (state: RootState, category: string, id: number) => id\r\n// result of output selector\r\nconst finalResult =\r\n  // The result function\r\n  items.filter(item => item.category === category && item.id !== id)\r\n```\r\n\r\nIn this example, `selectItemId` expects that its second argument will be some simple value, while `selectVendorName` expects that the second argument is an object. If you call `selectItemById(state, 42)`, `selectVendorName` will break because it's trying to access `42.name`. Reselect's TS types should detect this and prevent compilation:\r\n\r\n```ts\r\nconst selectItems = (state: RootState) => state.items\r\n\r\n// expects a number as the second argument\r\nconst selectItemId = (state: RootState, itemId: number) => itemId\r\n\r\n// expects an object as the second argument\r\nconst selectVendorName = (\r\n  state: RootState,\r\n  vendor: { id: number; name: string }\r\n) => vendor.name\r\n\r\nconst selectItemById = createSelector(\r\n  [selectItems, selectItemId, selectVendorName],\r\n  (items, itemId, vendorName) => items[itemId]\r\n)\r\n```\r\n\r\n</details>\r\n\r\n### Can the memoization behavior be customized?\r\n\r\nYes. The built-in `lruMemoize` memoizer works great for a lot of use cases, but it can be customized or swapped out for a different memoizer. See [these examples](#customize-equalitycheck-for-lrumemoize).\r\n\r\n### How do I test a selector?\r\n\r\nSelectors are pure functions - for a given input, a selector should always produce the same result. For this reason they are simple to unit test: call the selector with a set of inputs, and assert that the result value matches an expected shape.\r\n\r\n<details><summary><b>Detailed Explanation: Testing Selectors</b></summary>\r\n\r\n```ts\r\ninterface RootState {\r\n  todos: { id: number; completed: boolean }[]\r\n  alerts: { id: number; read: boolean }[]\r\n}\r\n\r\nconst state: RootState = {\r\n  todos: [\r\n    { id: 0, completed: false },\r\n    { id: 1, completed: true }\r\n  ],\r\n  alerts: [\r\n    { id: 0, read: false },\r\n    { id: 1, read: true }\r\n  ]\r\n}\r\n\r\n// With `Vitest` or `Jest`\r\ntest('selector unit test', () => {\r\n  const selectTodoIds = createSelector(\r\n    [(state: RootState) => state.todos],\r\n    todos => todos.map(({ id }) => id)\r\n  )\r\n  const firstResult = selectTodoIds(state)\r\n  const secondResult = selectTodoIds(state)\r\n  // Reference equality should pass.\r\n  expect(firstResult).toBe(secondResult)\r\n  // Deep equality should also pass.\r\n  expect(firstResult).toStrictEqual(secondResult)\r\n  selectTodoIds(state)\r\n  selectTodoIds(state)\r\n  selectTodoIds(state)\r\n  // The result function should not recalculate.\r\n  expect(selectTodoIds.recomputations()).toBe(1)\r\n  // input selectors should not recalculate.\r\n  expect(selectTodoIds.dependencyRecomputations()).toBe(1)\r\n})\r\n\r\n// With `Chai`\r\ntest('selector unit test', () => {\r\n  const selectTodoIds = createSelector(\r\n    [(state: RootState) => state.todos],\r\n    todos => todos.map(({ id }) => id)\r\n  )\r\n  const firstResult = selectTodoIds(state)\r\n  const secondResult = selectTodoIds(state)\r\n  // Reference equality should pass.\r\n  expect(firstResult).to.equal(secondResult)\r\n  // Deep equality should also pass.\r\n  expect(firstResult).to.deep.equal(secondResult)\r\n  selectTodoIds(state)\r\n  selectTodoIds(state)\r\n  selectTodoIds(state)\r\n  // The result function should not recalculate.\r\n  expect(selectTodoIds.recomputations()).to.equal(1)\r\n  // input selectors should not recalculate.\r\n  expect(selectTodoIds.dependencyRecomputations()).to.equal(1)\r\n})\r\n```\r\n\r\n</details>\r\n\r\n### Can I share a selector across multiple component instances?\r\n\r\nYes, although if they pass in different arguments, you will need to handle that in order for memoization to work consistently:\r\n\r\n- Pass a larger `maxSize` if using `lruMemoize` ( as of 4.1.0+)\r\n- Use [`weakMapMemoize`](#weakmapmemoize) (as of 5.0.0+)\r\n\r\n### Are there TypeScript Typings?\r\n\r\nYes! Reselect is now written in TypeScript itself, so they should Just Work™.\r\n\r\n### I am seeing a TypeScript error: `Type instantiation is excessively deep and possibly infinite`\r\n\r\nStarting in 5.0.0 you should be able to nest up to 30 selectors, but in case you still run into this issue, you can refer to [this\r\ncomment](https://github.com/reduxjs/reselect/issues/534#issuecomment-956708953) for a discussion of the problem, as\r\nrelating to nested selectors.\r\n\r\n### How can I make a [curried](https://github.com/hemanth/functional-programming-jargon#currying) selector?\r\n\r\nSelectors that take arguments are commonly used inside of React-Redux's `useSelector` by using a closure to pass along the extra arguments:\r\n\r\n```ts\r\nfunction TodosList({ category }) {\r\n  const filteredTodos = useSelector(state =>\r\n    selectTodosByCategory(state, category)\r\n  )\r\n}\r\n```\r\n\r\nIf you prefer to use a curried form instead, you can create a curried selector with this recipe:\r\n\r\n<details><summary><b>Detailed Explanation: Creating Curried Selectors</b></summary>\r\n\r\n```ts\r\nconst currySelector = <\r\n  State,\r\n  Result,\r\n  Params extends readonly any[],\r\n  AdditionalFields\r\n>(\r\n  selector: ((state: State, ...args: Params) => Result) & AdditionalFields\r\n) => {\r\n  const curriedSelector = (...args: Params) => {\r\n    return (state: State) => {\r\n      return selector(state, ...args)\r\n    }\r\n  }\r\n  return Object.assign(curriedSelector, selector)\r\n}\r\n\r\nconst selectTodoByIdCurried = currySelector(\r\n  createSelector(\r\n    [(state: RootState) => state.todos, (state: RootState, id: number) => id],\r\n    (todos, id) => todos.find(todo => todo.id === id)\r\n  )\r\n)\r\n```\r\n\r\nOr for reusability you can do this:\r\n\r\n```ts\r\nimport type { weakMapMemoize, SelectorArray, UnknownMemoizer } from 'reselect'\r\nimport { createSelector } from 'reselect'\r\n\r\nexport const createCurriedSelector = <\r\n  InputSelectors extends SelectorArray,\r\n  Result,\r\n  OverrideMemoizeFunction extends UnknownMemoizer = typeof weakMapMemoize,\r\n  OverrideArgsMemoizeFunction extends UnknownMemoizer = typeof weakMapMemoize\r\n>(\r\n  ...args: Parameters<\r\n    typeof createSelector<\r\n      InputSelectors,\r\n      Result,\r\n      OverrideMemoizeFunction,\r\n      OverrideArgsMemoizeFunction\r\n    >\r\n  >\r\n) => {\r\n  return currySelector(createSelector(...args))\r\n}\r\n```\r\n\r\nThis:\r\n\r\n```ts\r\nconst selectTodoById = createSelector(\r\n  [(state: RootState) => state.todos, (state: RootState, id: number) => id],\r\n  (todos, id) => todos.find(todo => todo.id === id)\r\n)\r\n\r\nselectTodoById(state, 0)\r\n```\r\n\r\nIs the same as this:\r\n\r\n```ts\r\nselectTodoByIdCurried(0)(state)\r\n```\r\n\r\nAs before you had to do this:\r\n\r\n```ts\r\nconst todoById = useSelector(state => selectTodoById(state, id))\r\n```\r\n\r\nNow you can do this:\r\n\r\n```ts\r\nconst todoById = useSelector(selectTodoByIdCurried(id))\r\n```\r\n\r\nAnother thing you can do if you are using [React-Redux] is create a custom hook factory function:\r\n\r\n```ts\r\nimport { useSelector } from 'react-redux'\r\n\r\nexport const createParametricSelectorHook = <\r\n  Result,\r\n  Params extends readonly unknown[]\r\n>(\r\n  selector: (state: RootState, ...params: Params) => Result\r\n) => {\r\n  return (...args: Params) => {\r\n    return useSelector(state => selector(state, ...args))\r\n  }\r\n}\r\n\r\nconst useSelectTodo = createParametricSelectorHook(selectTodoById)\r\n```\r\n\r\nAnd then inside your component:\r\n\r\n```tsx\r\nimport type { FC } from 'react'\r\n\r\ninterface Props {\r\n  id: number\r\n}\r\n\r\nconst MyComponent: FC<Props> = ({ id }) => {\r\n  const todo = useSelectTodo(id)\r\n  return <div>{todo.title}</div>\r\n}\r\n```\r\n\r\n</details>\r\n\r\n### How can I make pre-typed version of [`createSelector`](#createselector) for my root state?\r\n\r\nWhen used with Redux, it's typical to have all input selectors take `(state: RootState)` as their first argument. Creating a pre-typed version of `createSelector` can shorten that repetition.\r\n\r\n<details><summary><b>Detailed Explanation: Pre-Typed `createSelector`</b></summary>\r\n\r\nYou can create a custom typed version of [`createSelector`] by defining a utility type that extends the original [`createSelector`] function. Here's an example:\r\n\r\n```ts\r\nimport type {\r\n  OutputSelector,\r\n  Selector,\r\n  SelectorArray,\r\n  UnknownMemoizer,\r\n  weakMapMemoize\r\n} from 'reselect'\r\nimport { createSelector } from 'reselect'\r\n\r\ninterface RootState {\r\n  todos: { id: number; completed: boolean }[]\r\n  alerts: { id: number; read: boolean }[]\r\n}\r\n\r\nexport type TypedCreateSelector<\r\n  State,\r\n  MemoizeFunction extends UnknownMemoizer = typeof weakMapMemoize,\r\n  ArgsMemoizeFunction extends UnknownMemoizer = typeof weakMapMemoize\r\n> = <\r\n  InputSelectors extends readonly Selector<State>[],\r\n  Result,\r\n  OverrideMemoizeFunction extends UnknownMemoizer = MemoizeFunction,\r\n  OverrideArgsMemoizeFunction extends UnknownMemoizer = ArgsMemoizeFunction\r\n>(\r\n  ...createSelectorArgs: Parameters<\r\n    typeof createSelector<\r\n      InputSelectors,\r\n      Result,\r\n      OverrideMemoizeFunction,\r\n      OverrideArgsMemoizeFunction\r\n    >\r\n  >\r\n) => ReturnType<\r\n  typeof createSelector<\r\n    InputSelectors,\r\n    Result,\r\n    OverrideMemoizeFunction,\r\n    OverrideArgsMemoizeFunction\r\n  >\r\n>\r\n\r\nexport const createAppSelector: TypedCreateSelector<RootState> = createSelector\r\n```\r\n\r\n> [!WARNING]: This approach currently only supports [input selectors] provided as a single array.\r\n\r\n</details>\r\n\r\n### What if I want to use [`createSelector`](#createselector) without memoization?\r\n\r\nThere may be rare cases when you might want to use `createSelector` for its composition syntax, but without any memoization applied. In that case, create an [`identity function`][Identity Function] and use it as the memoizers:\r\n\r\n```ts\r\nconst identity = <Func extends (...args: any[]) => any>(func: Func) => func\r\n\r\nconst createNonMemoizedSelector = createSelectorCreator({\r\n  memoize: identity,\r\n  argsMemoize: identity\r\n})\r\n```\r\n\r\n<div align=\"right\">[ <a href=\"#table-of-contents\">↑ Back to top ↑</a> ]</div>\r\n\r\n---\r\n\r\n## External References\r\n\r\n<details><summary><b>Click to expand</b></summary>\r\n\r\n- [**`WeakMap`**][`WeakMap`]\r\n- [**`Reference Equality Check`**][Reference Equality Check]\r\n- [**`Memoization`**][Memoization]\r\n- [**`Identity Function`**][Identity Function]\r\n\r\n</details>\r\n\r\n## Related Projects\r\n\r\n### [re-reselect](https://github.com/toomuchdesign/re-reselect)\r\n\r\nEnhances Reselect selectors by wrapping [`createSelector`] and returning a memoized collection of selectors indexed with the cache key returned by a custom resolver function.\r\n\r\nUseful to reduce selectors recalculation when the same selector is repeatedly called with one/few different arguments.\r\n\r\n### [reselect-tools](https://github.com/skortchmark9/reselect-tools)\r\n\r\n- Measure selector recomputations across the app and identify performance bottlenecks\r\n- Check selector dependencies, inputs, outputs, and recomputations at any time with the chrome extension\r\n- Statically export a JSON representation of your selector graph for further analysis\r\n\r\n### [reselect-debugger](https://github.com/vlanemcev/reselect-debugger-flipper)\r\n\r\n[Flipper plugin](https://github.com/vlanemcev/flipper-plugin-reselect-debugger) and [the connect app](https://github.com/vlanemcev/reselect-debugger-flipper) for debugging selectors in **React Native Apps**.\r\n\r\nInspired by Reselect Tools, so it also has all functionality from this library and more, but only for React Native and Flipper.\r\n\r\n- Selectors Recomputations count in live time across the App for identify performance bottlenecks\r\n- Highlight most recomputed selectors\r\n- Dependency Graph\r\n- Search by Selectors Graph\r\n- Selectors Inputs\r\n- Selectors Output (In case if selector not dependent from external arguments)\r\n- Shows \"Not Memoized (NM)\" selectors\r\n\r\n<div align=\"right\">[ <a href=\"#table-of-contents\">↑ Back to top ↑</a> ]</div>\r\n\r\n---\r\n\r\n## License\r\n\r\nMIT\r\n\r\n## Prior Art and Inspiration\r\n\r\n<details><summary><b>Click to expand</b></summary>\r\n\r\nOriginally inspired by getters in [NuclearJS](https://github.com/optimizely/nuclear-js.git), [subscriptions](https://github.com/Day8/re-frame#just-a-read-only-cursor) in [re-frame](https://github.com/Day8/re-frame) and this [proposal](https://github.com/reduxjs/redux/pull/169) from [speedskater](https://github.com/speedskater).\r\n\r\n[typescript-badge]: https://img.shields.io/badge/TypeScript-v4%2E7%2B-007ACC?style=for-the-badge&logo=TypeScript&logoColor=black&labelColor=blue&color=gray\r\n[build-badge]: https://img.shields.io/github/actions/workflow/status/reduxjs/reselect/build-and-test-types.yml?branch=master&style=for-the-badge\r\n[build]: https://github.com/reduxjs/reselect/actions/workflows/build-and-test-types.yml\r\n[npm-badge]: https://img.shields.io/npm/v/reselect.svg?style=for-the-badge\r\n[npm]: https://www.npmjs.org/package/reselect\r\n[coveralls-badge]: https://img.shields.io/coveralls/reduxjs/reselect/master.svg?style=for-the-badge\r\n[coveralls]: https://coveralls.io/github/reduxjs/reselect\r\n\r\n<!-- External Links -->\r\n\r\n[`WeakMap`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap 'WeakMap'\r\n[Reference Equality Check]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality 'Reference Equality Check'\r\n[Memoization]: https://en.wikipedia.org/wiki/Memoization 'Memoization'\r\n[Identity Function]: https://en.wikipedia.org/wiki/Identity_function 'Identity Function'\r\n[`useMemo`]: https://react.dev/reference/react/useMemo#usememo 'useMemo'\r\n[`useCallback`]: https://react.dev/reference/react/useCallback#usecallback 'useCallback'\r\n[`re-reselect`]: https://github.com/toomuchdesign/re-reselect 're-reselect'\r\n[Redux]: https://redux.js.org 'Redux'\r\n[React]: https://react.dev 'React'\r\n[React-Redux]: https://react-redux.js.org 'React-Redux'\r\n\r\n<!-- Internal Links -->\r\n\r\n[selector]: #selector-function 'Selector Function'\r\n[input selectors]: #input-selectors 'Input Selectors'\r\n[output selector]: #output-selector 'Output Selector'\r\n[result function]: #result-function 'Result Function'\r\n[`dependencies`]: #dependencies 'Dependencies'\r\n[**_Cascading Memoization_**]: #cascading-memoization 'Cascading Memoization'\r\n[output selector fields]: #output-selector-fields 'Output Selector Fields'\r\n[`createSelector`]: #createselectorinputselectors--inputselectors-resultfunc-createselectoroptions 'createSelector'\r\n[`createSelectorCreator`]: #createselectorcreatormemoize--options-memoizeoptions 'createSelectorCreator'\r\n[`lruMemoize`]: #lrumemoizefunc-equalitycheckoroptions--referenceequalitycheck 'lruMemoize'\r\n[`weakMapMemoize`]: #weakmapmemoizefunc---since-500 'weakMapMemoize'\r\n[`unstable_autotrackMemoize`]: #unstable_autotrackmemoizefunc---since-500 'unstable_autotrackMemoize'\r\n[`createStructuredSelector`]: #createstructuredselector-inputSelectorsObject--selectorcreator--createselector 'createStructuredSelector'\r\n\r\n</details>\r\n\r\n<div align=\"right\">[ <a href=\"#table-of-contents\">↑ Back to top ↑</a> ]</div>\r\n\r\n---\r\n","authors":["Lee Bannard","Robert Binna","Martijn Faassen","Philip Spitzlinger"],"exports":{".":{"types":"./dist/reselect.d.ts","import":"./dist/reselect.mjs","default":"./dist/cjs/reselect.cjs"},"./package.json":"./package.json"},"gitHead":"b7a1015366893ffd20c89867c4a055bd416342cf","scripts":{"lint":"eslint src test","test":"node --expose-gc ./node_modules/vitest/dist/cli-wrapper.js run","bench":"vitest --run bench --mode production","build":"tsup","clean":"rimraf dist","format":"prettier --write \"{src,test}/**/*.{js,ts}\" \"docs/**/*.md\"","prepack":"yarn build","test:cov":"vitest run --coverage","docs:build":"yarn --cwd website build","docs:clear":"yarn --cwd website clear","docs:serve":"yarn --cwd website serve","docs:start":"yarn --cwd website start","test:watch":"node --expose-gc ./node_modules/vitest/dist/cli-wrapper.js watch","type-check":"vitest --run typecheck","test:typescript":"tsc --noEmit -p typescript_test/tsconfig.json","type-check:trace":"vitest --run typecheck && tsc --noEmit -p typescript_test/tsconfig.json --generateTrace trace && npx @typescript/analyze-trace trace && rimraf trace"},"_npmUser":{"name":"acemarke","email":"mark.erikson@gmail.com"},"repository":{"url":"git+https://github.com/reduxjs/reselect.git","type":"git"},"_npmVersion":"9.8.1","description":"Selectors for Redux.","directories":{},"sideEffects":false,"_nodeVersion":"18.18.2","_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"tsup":"^6.7.0","jsdom":"^23.0.0","react":"^18.2.0","eslint":"^8.0.1","lodash":"^4.17.21","rimraf":"^3.0.2","vitest":"^0.34","shelljs":"^0.8.5","prettier":"^2.7.1","react-dom":"^18.2.0","typescript":"5.2","memoize-one":"^6.0.0","react-redux":"^9.0.0-rc.0","@types/react":"^18.2.38","@types/lodash":"^4.14.175","micro-memoize":"^4.0.9","@types/shelljs":"^0.8.11","lodash.memoize":"^4.1.2","@reduxjs/toolkit":"^2.0.0-rc.1","@types/react-dom":"^18.2.17","eslint-plugin-react":"^7.26.1","netlify-plugin-cache":"^1.0.3","@testing-library/react":"^14.1.2","eslint-plugin-typescript":"0.14.0","@typescript-eslint/parser":"^6","@typescript/analyze-trace":"^0.10.1","@typescript-eslint/eslint-plugin":"^6","@typescript-eslint/eslint-plugin-tslint":"^6"},"_npmOperationalInternal":{"tmp":"tmp/reselect_5.0.0-rc.1_1701489153000_0.8080394777376823","host":"s3://npm-registry-packages"},"publish_time":1701489153272,"_cnpm_publish_time":1701489153272,"dist-tags":{"alpha":"5.0.0-alpha.2","beta":"5.0.0-beta.1","latest":"5.3.0","next":"5.0.0-rc.0","rc":"5.0.0-rc.1","rc1":"3.0.0-beta.1"}}