Can you assign setState to ref attribute?

Опубликовано: 28 Март 2026
на канале: UI Engineering
841
78

What setState and refCallback have in common?
Unintuitive React Pattern that can help synchronize DOM Elements with Render Cycle.

⏱️Timestamps:
00:00 - Why assigning setState in ref is unintuitive
01:00 - Example from Popper.js
02:27 - How does it work?
03:08 - Is it safe?
05:24 - Is it breaking React Rules?
06:57 - Why would you want to use it?
09:31 - Lessons learned: When to use it

📖 Acknowledgments and further reading:
Popper Example: https://popper.js.org/react-popper/v2...
Popper, how it works explained: https://github.com/floating-ui/react-...
React's GitHub Discussion: https://github.com/facebook/react/iss...