Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connect: pass ownProps to areStatesEqual #1952

Merged
merged 1 commit into from Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/api/connect.md
Expand Up @@ -236,7 +236,7 @@ When `options.pure` is true, `connect` performs several equality checks that are

We provide a few examples in the following sections.

#### `areStatesEqual: (next: Object, prev: Object) => boolean`
#### `areStatesEqual: (next: Object, prev: Object, nextOwnProps: Object, prevOwnProps: Object) => boolean`

- default value: `strictEqual: (next, prev) => prev === next`

Expand All @@ -249,7 +249,7 @@ const areStatesEqual = (next, prev) =>
prev.entities.todos === next.entities.todos
```

You may wish to override `areStatesEqual` if your `mapStateToProps` function is computationally expensive and is also only concerned with a small slice of your state. The example above will effectively ignore state changes for everything but that slice of state.
You may wish to override `areStatesEqual` if your `mapStateToProps` function is computationally expensive and is also only concerned with a small slice of your state. The example above will effectively ignore state changes for everything but that slice of state. Additionally, `areStatesEqual` provides `nextOwnProps` and `prevOwnProps` to allow for more effective scoping of your state which your connected component is interested in, if needed.

_Example 2_

Expand Down
2 changes: 1 addition & 1 deletion src/connect/selectorFactory.js
Expand Up @@ -73,7 +73,7 @@ export function pureFinalPropsSelectorFactory(

function handleSubsequentCalls(nextState, nextOwnProps) {
const propsChanged = !areOwnPropsEqual(nextOwnProps, ownProps)
const stateChanged = !areStatesEqual(nextState, state)
const stateChanged = !areStatesEqual(nextState, state, nextOwnProps, ownProps)
state = nextState
ownProps = nextOwnProps

Expand Down