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 }}
This repository was archived by the owner on Jan 1, 2025. It is now read-only.
Custom hooks that have custom dependency arrays can't be statically analyzed by the react-hooks linter rule, and can't have their dependencies automatically tracked. Because of this, I'd suggest either:
Accept a callback and add that callback to the deps array of the internal useCallback. It'll make the callback on each render, or if the passed callback is useCallback'd, whenever the passed callback is recreated
Use the 'effect ref' pattern, so the end user can always pass a flat callback, but the callback function doesn't have to be a part of the deps array:
functionuseRecoilCallback(fn){constfnRef=useRef(fn)useEffect(()=>{fnRef.current=fn})returnuseCallback(()=>{// read fnRef.current instead of fn},[some,deps])}
I think 1. is "more correct" and would result in less bugs both internally and for the end user, but 2. would result in better UX, since 1. would require the user to useCallback/useMemo themselves if they wanted a properly recreated callback. A note in the docs about that might help, but those are fairly easy to miss 😅
Either way, I think this change will give a better UX when working with the hooks lint rule, with less surprises in general
Custom hooks that have custom dependency arrays can't be statically analyzed by the react-hooks linter rule, and can't have their dependencies automatically tracked. Because of this, I'd suggest either:
Accept a callback and add that callback to the deps array of the internal
useCallback. It'll make the callback on each render, or if the passed callback isuseCallback'd, whenever the passed callback is recreatedUse the 'effect ref' pattern, so the end user can always pass a flat callback, but the callback function doesn't have to be a part of the deps array:
I think 1. is "more correct" and would result in less bugs both internally and for the end user, but 2. would result in better UX, since 1. would require the user to
useCallback/useMemothemselves if they wanted a properly recreated callback. A note in the docs about that might help, but those are fairly easy to miss 😅Either way, I think this change will give a better UX when working with the hooks lint rule, with less surprises in general