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/rerenders: useMemo to avoid unnecessary rerenders #945

Merged
merged 4 commits into from
Dec 6, 2022

Conversation

stavros-liaskos
Copy link
Contributor

  • All new/changed/fixed functionality is covered by tests N/A
  • I have added documentation for all new/changed functionality N/A

📋 Changes

useContext is triggering unnecessary re-renders. With useMemo this can be avoided as described here.

tl;tr
I noticed this when I integrated why-did-you-render to release-raccoon. Atm it is using 2 contexts, I implemented the above fix to ThemeProvider and this PR takes care of fixing this in useUser too.

📎 References

🎯 Testing

Clicking on the Home btn calls the hook again but returns same results different objects that are equal by value.
withoutFix
withUseMemo

@vercel
Copy link

vercel bot commented Dec 6, 2022

@stavros-liaskos is attempting to deploy a commit to the Auth0 Team on Vercel.

A member of the Team first needs to authorize it.

@adamjmcgrath
Copy link
Contributor

adamjmcgrath commented Dec 6, 2022

Thanks for your contribution @stavros-liaskos!

Could you remove why-did-you-render and add a regression test to the SDK similar to https://github.com/auth0/auth0-react/pull/318/files#diff-50f0ae9241a4ab6bc7b4c79924a45f52f654e4a03ad982942b68e0142a287877

adamjmcgrath
adamjmcgrath previously approved these changes Dec 6, 2022
Copy link
Contributor

@adamjmcgrath adamjmcgrath left a comment

Choose a reason for hiding this comment

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

@adamjmcgrath adamjmcgrath changed the base branch from vNext to main December 6, 2022 17:57
@adamjmcgrath adamjmcgrath dismissed their stale review December 6, 2022 17:57

The base branch was changed.

@stavros-liaskos
Copy link
Contributor Author

Thanks @stavros-liaskos

Thank you @adamjmcgrath

@adamjmcgrath adamjmcgrath merged commit 98b31a1 into auth0:main Dec 6, 2022
@adamjmcgrath adamjmcgrath mentioned this pull request Dec 9, 2022
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