Skip to content

getFlashMessages selector causes re-renders #48

Description

@chawes13

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions