Skip to content

Commit 29891c7

Browse files
committed
Clarify when it's necessary to copy selectors
Previously, it was unclear for people skimming the docs that the advice found in the `Sharing Selectors Across Multiple Components` section only applies for those trying to solve the specific problem mentioned in the previous section. As a result, I'm sure some people were padding private copies of selectors to different components even in situations where they didn't need to. This makes the documentation more clear.
1 parent 865f7de commit 29891c7

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const totalSelector = createSelector(
4242
- [Composing Selectors](#composing-selectors)
4343
- [Connecting a Selector to the Redux Store](#connecting-a-selector-to-the-redux-store)
4444
- [Accessing React Props in Selectors](#accessing-react-props-in-selectors)
45-
- [Sharing Selectors Across Multiple Components](#sharing-selectors-across-multiple-components)
45+
- [Sharing Selectors with Props Across Multiple Components](#sharing-selectors-across-multiple-components)
4646
- [API](#api)
4747
- [`createSelector`](#createselectorinputselectors--inputselectors-resultfunc)
4848
- [`defaultMemoize`](#defaultmemoizefunc-equalitycheck--defaultequalitycheck)
@@ -297,11 +297,11 @@ export default VisibleTodoList
297297

298298
A selector created with `createSelector` 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.
299299

300-
### Sharing Selectors Across Multiple Components
300+
### Sharing Selectors with Props Across Multiple Components
301301

302302
> The examples in this section require React Redux v4.3.0 or greater
303303
304-
In order to share a selector across multiple `VisibleTodoList` components **and** retain memoization, each instance of the component needs its own private copy of the selector.
304+
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.
305305

306306
Let’s create a function named `makeGetVisibleTodos` that returns a new copy of the `getVisibleTodos` selector each time it is called:
307307

0 commit comments

Comments
 (0)