Skip to content

Commit 043517e

Browse files
docs(hooks): clarify useSelector re-runs on render (#1526)
* docs(hooks): clarify useSelector re-runs on render * Update hooks.md * update versioned_docs
1 parent e64b610 commit 043517e

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

docs/api/hooks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Allows you to extract data from the Redux store state, using a selector function
4040

4141
> **Note**: The selector function should be [pure](https://en.wikipedia.org/wiki/Pure_function) since it is potentially executed multiple times and at arbitrary points in time.
4242
43-
The selector is approximately equivalent to the [`mapStateToProps` argument to `connect`](../using-react-redux/connect-extracting-data-with-mapStateToProps.md) conceptually. The selector will be called with the entire Redux store state as its only argument. The selector will be run whenever the function component renders. `useSelector()` will also subscribe to the Redux store, and run your selector whenever an action is dispatched.
43+
The selector is approximately equivalent to the [`mapStateToProps` argument to `connect`](../using-react-redux/connect-extracting-data-with-mapStateToProps.md) conceptually. The selector will be called with the entire Redux store state as its only argument. The selector will be run whenever the function component renders (unless its reference hasn't changed since a previous render of the component so that a cached result can be returned by the hook without re-running the selector). `useSelector()` will also subscribe to the Redux store, and run your selector whenever an action is dispatched.
4444

4545
However, there are some differences between the selectors passed to `useSelector()` and a `mapState` function:
4646

@@ -57,7 +57,7 @@ You may call `useSelector()` multiple times within a single function component.
5757
### Equality Comparisons and Updates
5858

5959
When the function component renders, the provided selector function will be called and its result will be returned
60-
from the `useSelector()` hook. (A cached result may be returned if the selector has been run and hasn't changed.)
60+
from the `useSelector()` hook. (A cached result may be returned by the hook without re-running the selector if it's the same function reference as on a previous render of the component.)
6161

6262
However, when an action is dispatched to the Redux store, `useSelector()` only forces a re-render if the selector result
6363
appears to be different than the last result. As of v7.1.0-alpha.5, the default comparison is a strict `===` reference

website/versioned_docs/version-7.1/api/hooks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Allows you to extract data from the Redux store state, using a selector function
4141

4242
> **Note**: The selector function should be [pure](https://en.wikipedia.org/wiki/Pure_function) since it is potentially executed multiple times and at arbitrary points in time.
4343
44-
The selector is approximately equivalent to the [`mapStateToProps` argument to `connect`](../using-react-redux/connect-extracting-data-with-mapStateToProps.md) conceptually. The selector will be called with the entire Redux store state as its only argument. The selector will be run whenever the function component renders. `useSelector()` will also subscribe to the Redux store, and run your selector whenever an action is dispatched.
44+
The selector is approximately equivalent to the [`mapStateToProps` argument to `connect`](../using-react-redux/connect-extracting-data-with-mapStateToProps.md) conceptually. The selector will be called with the entire Redux store state as its only argument. The selector will be run whenever the function component renders (unless its reference hasn't changed since a previous render of the component so that a cached result can be returned by the hook without re-running the selector). `useSelector()` will also subscribe to the Redux store, and run your selector whenever an action is dispatched.
4545

4646
However, there are some differences between the selectors passed to `useSelector()` and a `mapState` function:
4747

@@ -58,7 +58,7 @@ You may call `useSelector()` multiple times within a single function component.
5858
### Equality Comparisons and Updates
5959

6060
When the function component renders, the provided selector function will be called and its result will be returned
61-
from the `useSelector()` hook. (A cached result may be returned if the selector has been run and hasn't changed.)
61+
from the `useSelector()` hook. (A cached result may be returned by the hook without re-running the selector if it's the same function reference as on a previous render of the component.)
6262

6363
However, when an action is dispatched to the Redux store, `useSelector()` only forces a re-render if the selector result
6464
appears to be different than the last result. As of v7.1.0-alpha.5, the default comparison is a strict `===` reference

0 commit comments

Comments
 (0)