Is it safe to mutate a ref in the render phase? #1284
Unanswered
vlad-khitev-axon
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This library uses
useSyncedRef
extensively.React docs recommend avoiding updating the ref during the render phase except for initialization (docs reference). For example:
According to this answer on StackOverflow, the problem can arise when working with React concurrent mode. If it's enabled, and the render phase gets interrupted, the ref value can end up out of sync with the actual state of the component. I'm unsure how this library will behave in practice when someone enables the concurrent mode.
The modern competitor library usehooks never mutates the ref in the render function, except for adding some properties in
useSet
anduseMap
.So, how safe is
useSyncedRef
?Beta Was this translation helpful? Give feedback.
All reactions