You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A selector created with `createSelector` has a cache size of 1 and only returns the cached value when its set of arguments is the same as its previous set of arguments. If we alternate between rendering `<VisibleTodoList listId="1" />` and `<VisibleTodoList listId="2" />`, the shared selector will alternate between receiving `{listId: 1}` and `{listId: 2}` as its `props` argument. This will cause the arguments to be different on each call, so the selector will always recompute instead of returning the cached value. We’ll see how to overcome this limitation in the next section.
318
318
319
-
### Sharing Selectors with Props Across Multiple Components
319
+
### Sharing Selectors with Props Across Multiple Component Instances
320
320
321
321
> The examples in this section require React Redux v4.3.0 or greater
322
322
323
323
> An alternative approach be found in [re-reselect](https://github.com/toomuchdesign/re-reselect)
324
324
325
-
To share a selector across multiple `VisibleTodoList`components while passing in `props`**and** retaining memoization, each instance of the component needs its own private copy of the selector.
325
+
To share a selector across multiple `VisibleTodoList`instances while passing in `props`**and** retaining memoization, each instance of the component needs its own private copy of the selector.
326
326
327
327
Let’s create a function named `makeGetVisibleTodos` that returns a new copy of the `getVisibleTodos` selector each time it is called:
If a selector's input is updated by an operation that always returns a new object, it may be performing unnecessary recomputations. See [here](#q-why-is-my-selector-recomputing-when-the-input-state-stays-the-same) for a discussion on the pros and cons of using a deep equality check like `Immutable.is` to eliminate unnecessary recomputations.
932
932
933
-
### Q: Can I share a selector across multiple components?
933
+
### Q: Can I share a selector across multiple component instances?
934
934
935
-
A: Selectors created using `createSelector` only have a cache size of one. This can make them unsuitable for sharing across multiple components if the arguments to the selector are different for each instance of the component. There are a couple of ways to get around this:
935
+
A: Selectors created using `createSelector` only have a cache size of one. This can make them unsuitable for sharing across multiple instances if the arguments to the selector are different for each instance of the component. There are a couple of ways to get around this:
936
936
937
-
* Create a factory function which returns a new selector for each instance of the component. There is built-in support for factory functions in React Redux v4.3 or higher. See [here](#sharing-selectors-with-props-across-multiple-components) for an example.
937
+
* Create a factory function which returns a new selector for each instance of the component. There is built-in support for factory functions in React Redux v4.3 or higher. See [here](#sharing-selectors-with-props-across-multiple-component-instances) for an example.
938
938
939
939
* Create a custom selector with a cache size greater than one.
0 commit comments