-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Add useRef usage example for detecting DOM changes #7372
base: main
Are you sure you want to change the base?
Add useRef usage example for detecting DOM changes #7372
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Size changes📦 Next.js Bundle Analysis for react-devThis analysis was generated by the Next.js Bundle Analysis action. 🤖 This PR introduced no changes to the JavaScript bundle! 🙌 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see the second part of #7372 (comment). don't add troubleshooting just yet, instead add a recipe to useRef
usage docs
+1 to @gaearon's feedback, just to add some more context: we have a usage example in the Learn docs and we also explain how Strict Mode helps catch this bug, but having it on this page too would be useful. In that thread I was actually saying we should document the behavior where callback refs unmount and remount when the callback function reference changes (so you should wrap it in useCallback) which isn't mentioned anywhere in the docs. Here's a sandbox showing the difference with/without useCallback. |
Thanks for the CodeSandbox! I did see that and was planning on adding a mention of this as well but I wrote this content to better understand the problem space for myself. I'll add this in this PR or a followup. |
3b5c317
to
17a3178
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrote this PR to be a usage example in useRef for detecting DOM changes
Inspired by @chaance's Bluesky post
Preview