The first argument, often a Redux root state object.
All additional arguments passed into the selector.
A derived value from the state.
The optional memoize function that is used to memoize the arguments
passed into the output selector generated by createSelector
(e.g., lruMemoize or weakMapMemoize).
When passed directly into createSelector, it overrides the
argsMemoize function initially passed into createSelectorCreator.
If none was initially provided, weakMapMemoize will be used.
ExperimentalCreates 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.
Design Tradeoffs for weakMapMemoize:
WeakMaps.lruMemoize, although likely a fraction slower.Use Cases for weakMapMemoize:
useSelector(state => selectSomeData(state, props.category))
A memoized function with a .clearCache() method attached.
interface RootState { items: { id: number; category: string; name: string }[] }
const selectItemsByCategory = createSelector( [ (state: RootState) => state.items, (state: RootState, category: string) => category ], (items, category) => items.filter(item => item.category === category), { memoize: weakMapMemoize, argsMemoize: weakMapMemoize } )
const createSelectorWeakMap = createSelectorCreator({ memoize: weakMapMemoize, argsMemoize: weakMapMemoize })
const selectItemsByCategory = createSelectorWeakMap( [ (state: RootState) => state.items, (state: RootState, category: string) => category ], (items, category) => items.filter(item => item.category === category) )
import { createSelector, weakMapMemoize } from 'reselect'
const selectItemsByCategory = createSelector(
[
(state: RootState) => state.items,
(state: RootState, category: string) => category
],
(items, category) => items.filter(item => item.category === category),
{ argsMemoize: weakMapMemoize }
)
The array of the input selectors used by createSelector to compose the
combiner (OutputSelectorFields.memoizedResultFunc memoizedResultFunc).
Counts the number of times the input selectors (OutputSelectorFields.dependencies dependencies)
have been recalculated. This is distinct from OutputSelectorFields.recomputations recomputations,
which tracks the recalculations of the result function.
The last result calculated by OutputSelectorFields.memoizedResultFunc memoizedResultFunc.
The memoize function that is used to memoize the OutputSelectorFields.resultFunc resultFunc
inside createSelector (e.g., lruMemoize or weakMapMemoize).
When passed directly into createSelector, it overrides the memoize function initially passed into createSelectorCreator.
ExperimentalCreates 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.
Design Tradeoffs for weakMapMemoize:
WeakMaps.lruMemoize, although likely a fraction slower.Use Cases for weakMapMemoize:
useSelector(state => selectSomeData(state, props.category))
A memoized function with a .clearCache() method attached.
interface RootState { items: { id: number; category: string; name: string }[] }
const selectItemsByCategory = createSelector( [ (state: RootState) => state.items, (state: RootState, category: string) => category ], (items, category) => items.filter(item => item.category === category), { memoize: weakMapMemoize, argsMemoize: weakMapMemoize } )
const createSelectorWeakMap = createSelectorCreator({ memoize: weakMapMemoize, argsMemoize: weakMapMemoize })
const selectItemsByCategory = createSelectorWeakMap( [ (state: RootState) => state.items, (state: RootState, category: string) => category ], (items, category) => items.filter(item => item.category === category) )
The memoized version of OutputSelectorFields.resultFunc resultFunc.
A function that takes input selectors' return values as arguments and returns a result. Otherwise known as resultFunc.
Return values of input selectors.
The return value of OutputSelectorFields.resultFunc resultFunc.
Counts the number of times OutputSelectorFields.memoizedResultFunc memoizedResultFunc has been recalculated.
Resets the count OutputSelectorFields.dependencyRecomputations dependencyRecomputations
for the input selectors (OutputSelectorFields.dependencies dependencies)
of a memoized selector.
Resets the count of OutputSelectorFields.recomputations recomputations count to 0.
The final function passed to createSelector. Otherwise known as the combiner.
A function that takes input selectors' return values as arguments and returns a result. Otherwise known as resultFunc.
Return values of input selectors.
The return value of OutputSelectorFields.resultFunc resultFunc.
A function that takes a state and returns data that is based on that state.