New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Can useMemo be used instead of useRef? #17962
Comments
You could create a ref object this way, but it would be less efficient since To illustrate this, you can compare the implementation of react/packages/react-reconciler/src/ReactFiberHooks.js Lines 907 to 920 in 434770c
To react/packages/react-reconciler/src/ReactFiberHooks.js Lines 1126 to 1156 in 434770c
Since both hooks are used frequently, it's important they perform optimally 😄 so they are implemented different. |
|
@yaofly2012 GitHub formats links that way, if you link to a specific file revision and line numbers.
|
Hi, just out of curiosity can
useMemo
be used instead ofuseRef
when doing it as following:Example:
It looks to me that both refs will be working just fine as DOM ref and as mutable value similar to instance fields in classes. Why then
useRef
is implemented differently comparing touseMemo
considering ReactFiberHooks.js code foruseRef
anduseMemo
?Thanks!
The text was updated successfully, but these errors were encountered: