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

getFlashMessages selector causes re-renders #48

Open
chawes13 opened this issue Jun 29, 2023 · 0 comments
Open

getFlashMessages selector causes re-renders #48

chawes13 opened this issue Jun 29, 2023 · 0 comments

Comments

@chawes13
Copy link
Collaborator

When using the useSelector hook, a console warning is shown instructing the user to memoize the result.
Image 2023-06-29 at 2 25 54 PM

Since getFlashMessages returns new array, it will always trigger a re-render of its component (the default comparator is shallow equals, i.e., ===).

This is especially worrisome because it's usually included in the top Layout component within our client repos and will trigger a re-render after every action is handled and updates state somewhere in the tree, which could have a cascading effect on triggering child re-renders throughout the app.

Potential solutions:

  • Don't export selectors
  • Use createSelector from reselect to memoize the selectors
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

No branches or pull requests

1 participant