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

Fix: Avoid re-render when user settings haven't changed for FilterProvider #3959

Merged
merged 1 commit into from
Feb 8, 2024

Conversation

bjoernricks
Copy link
Contributor

What

Avoid unnecessary re-renders in FilterProvider when getting the rowsPerPage settings from the redux store.

Why

The behavior of useSelector hook and "old" connect function is differently. useSelector uses identity comparison === for detecting if the returned object has changed and a re-render is necessary. In contrast connect uses shallow comparison. See https://react-redux.js.org/api/hooks#equality-comparisons-and-updates for all details.

Therefore to avoid re-renders in the FilterProvider we need to compare the contents of returned array from the user settings selector via shallowEqual because with every call a new array is created and the identity changes.

…vider

The behavior of `useSelector` and `connect` is differently.
`useSelector` uses identity comparison `===` for detecting if the
returned object has changed and a re-render is necessary and `connect`
uses shallow comparison. See https://react-redux.js.org/api/hooks#equality-comparisons-and-updates
for all details.

Therefore to avoid re-renders in the FilterProvider we need to compare
the contents of returned array from the user settings selector via
`shallowEqual` because with every call a new array is created and the
identity changes.
@bjoernricks bjoernricks requested a review from a team as a code owner February 8, 2024 15:57
@bjoernricks bjoernricks enabled auto-merge (rebase) February 8, 2024 15:58
Copy link

github-actions bot commented Feb 8, 2024

Conventional Commits Report

Type Number
Bug Fixes 1

🚀 Conventional commits found.

@bjoernricks bjoernricks merged commit c074336 into main Feb 8, 2024
11 checks passed
@bjoernricks bjoernricks deleted the fix-filterprovider-re-render-warning branch February 8, 2024 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants