Skip to content

avoids duplicate deref calculations in useStoreDependency #96

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

Merged
merged 1 commit into from
Mar 15, 2021

Conversation

gmcnaughton
Copy link
Contributor

cc @aem - another possible approach to #95

Avoids duplicate deref calculations in useStoreDependency. Only calculate the value once; use it to initialize state (if needed) and as the new value.

When the value changes, two deref calculations will still run:

  1. initial render/hook call
  2. re-render/hook call triggered by setting the new value in state

TODOs

  • linter, checker, and test are passing
  • any new public modules are exported from src/GeneralStore.js
  • version numbers are up to date in package.json
  • CHANGELOG.md is up to date

See HubSpot#95

Avoids duplicate deref calculations in `useStoreDependency`. Only
calculate once; use this result to initialize state (if necessary)
and as the next state.

When the value changes, two deref calculations will still run:

1. the initial render/hook call
2. the re-render/hook call triggered by setting the new value in state
@gmcnaughton gmcnaughton force-pushed the gcm/minimize-deref-calls branch from d963af0 to 06f93dd Compare March 15, 2021 13:47
@aem aem merged commit 9a190d4 into HubSpot:master Mar 15, 2021
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