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
Click "Toggle" button to unmount the second div node
Open console and look at the output, described by the following quote from the doc
If the ref callback is defined as an inline function, it will get called twice during updates, first with null and then again with the DOM element. This is because a new instance of the function is created with each render, so React needs to clear the old ref and set up the new one.
Hi @cdoublev ,
Actually "useCallback" returns a memoized function but when you call that function ("setRefs"), it creates and returns a new function every time.
The inner function is not memoized.
Hope it helps :).
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
useCallback
doesn't return a memoized function when used as a "higher order ref callback".https://codesandbox.io/s/snowy-tdd-wb8gu
https://reactjs.org/docs/refs-and-the-dom.html#caveats-with-callback-refs
What is the expected behavior?
https://reactjs.org/docs/hooks-reference.html#usecallback
It doesn't work with
useMemo
as well, even if #15774 looks similar. It works with a "standard" memoize function, like_.memoize
.As indicated in #17204, I was looking for a way to identify the unmounted node.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
React 16.11.0
The text was updated successfully, but these errors were encountered: