I noticed some places in the source code use the useCallbackRef, what is its main function? #1902
-
I guess the function of this hooks is used to simulate the useEvent that react has not yet available? But I see some other versions of mockups in the community that use useLayoutEffect instead of useEffect, my understanding is that the reason to use useLayoutEffect is to get the updated value at the render stage, while useEffect is executed asynchronously after the render stage, so using useEffect is not able to get the updated value in the render stage, so is useCallbackRef a problem in this particular case? Or is this special scenario intentionally ignored? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
We use it when we need a stable reference internally to a callback passed by the user which we can't guarantee has been memoized.
We created this long before that RFC, but I guess that is what
I'm not sure if there is an issue with us using |
Beta Was this translation helpful? Give feedback.
We use it when we need a stable reference internally to a callback passed by the user which we can't guarantee has been memoized.
We created this long before that RFC, but I guess that is what
useEvent
is, I haven't looked at the RFC but seems similar.