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
{{ message }}
Repository navigation
[Compiler Bug]: Compiler disagrees with exhaustive-deps linter on whether React.Ref<T>.current must be in a deps array #29160
I have a hook called useWorker() which creates and configures a WebWorker, returning it as a React.RefObject<Worker>, while careful to never perform a side effect during a render.
The compiler fails to compile my code as written, but succeeds if I specify workerRef.current as a dependency. But you're not supposed to express Ref.current as a dependency, per the react-hooks/exhaustive-deps linter:
React Hook React.useCallback has an unnecessary dependency: 'workerRef.current'. Either exclude it or remove the dependency array. Mutable values like 'workerRef.current' aren't valid dependencies because mutating them doesn't re-render the component. eslintreact-hooks/exhaustive-deps
Thanks for posting this. The compiler currently is only detecting refs that come from useRef(), so it doesn’t consider workerRef to be a ref in the example. We’ve gone back and forth on this, and I think I this issue is a good reminder that the -Ref suffix is a strong convention that we can consider building on (though there’s a bunch to think through). We’ll follow up here!
Reacted by Damian Stasik, Edgar Rodriguez, Olivier Tassinari, Huynh Duc Duy and Michael Altamirano
Reacted by Jeff Hemphill, Minh Nguyen and ellouzeskandercs
Activity
josephsavona commentedon May 18, 2024
Thanks for posting this. The compiler currently is only detecting refs that come from useRef(), so it doesn’t consider
workerRefto be a ref in the example. We’ve gone back and forth on this, and I think I this issue is a good reminder that the -Ref suffix is a strong convention that we can consider building on (though there’s a bunch to think through). We’ll follow up here![compiler] Treat ref-like named objects as refs
[compiler] Treat ref-like named objects as refs
[compiler] Treat ref-like named objects as refs (#29916)
jthemphill commentedon Dec 5, 2024
This issue is resolved when
enableTreatRefLikeIdentifiersAsRefsis active!Playground link
[compiler] Treat ref-like named objects as refs (react#29916)