You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
React docs recommend avoiding updating the ref during the render phase except for initialization (docs reference). For example:
// This might be unsafeconstuseHook=()=>{constref=useRef(null)ref.current=value}// One-time initialization is safeconstuseHook=()=>{constref=useRef(null)if(ref.current===null){ref.current=value}}
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 and useMap.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This library uses
useSyncedRefextensively.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
useSetanduseMap.So, how safe is
useSyncedRef?Beta Was this translation helpful? Give feedback.
All reactions