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

Refactor React object memoization using custom hook #6363

Merged
merged 3 commits into from May 18, 2022
Merged

Conversation

aduth
Copy link
Member

@aduth aduth commented May 17, 2022

Why:

  • More concise
  • Less error-prone in case of forgotten dependency key
  • May encourage memoization of objects when appropriate, by making it less tedious to accomplish

The original idea with this pattern is to try to avoid unnecessary renders of context consumers, where object context values would always be strictly unequal between renders unless memoized ({} !== {}). However, when trying to find some resources justifying the pattern, I found more resources in favor of avoiding "premature" memoization, or finding alternative ways to reduce re-renders ([1][2][3]). That being said, I still think there is some value in the memoization, and at least the first two points of the list above provide value for existing usage.

Copy link
Contributor

@zachmargolis zachmargolis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

aduth and others added 3 commits May 17, 2022 16:24
**Why**:

- More concise
- Less error-prone in case of forgotten dependency key
- May encourage memoization of objects when appropriate, by making it less tedious to accomplish

changelog: Internal, Performance, Create helper utility for front-end object memoization
See: #6363 (comment)
Co-Authored-By: Zach Margolis <zbmargolis@gmail.com>
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.

None yet

2 participants