-
Notifications
You must be signed in to change notification settings - Fork 559
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
[Hooks] Alternative useCallback implementation #83
Comments
Yeah, we've considered this. It's not clear however what pitfalls this would have in concurrent mode. The particular implementation you propose would definitely have issues (because it mutates during rendering). The one using an effect (like in our FAQ) would be a bit safer but isn't generic purpose (it requires the tree to commit first) and might also have pitfalls. We have another idea for how to solve this. I described it briefly in facebook/react#14099 and might add more info there later. Please participate in that issue if you're interested. Thanks! |
For someone searching for what is "async safe" or "mutation of ref during rendering" problem, it is described here:
|
Looks like ahooks/usePersistFn |
大佬也研究react么 |
We've submitted a proposal to solve this that's largely similar (but works a bit differently). Would appreciate your input. |
According to this page
useCallback(fn, inputs)
is equivalent touseMemo(() => fn, inputs)
I suggest another one (implemented with current hooks):
It has advantages:
inputs
, latest instance ofhandler
will be calleduseHandler
is constant for all rerendersThe text was updated successfully, but these errors were encountered: