-
Notifications
You must be signed in to change notification settings - Fork 560
[Feature Request]: useStateRef #199
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
Comments
Hi, thanks for your suggestion. RFCs should be submitted as pull requests, not issues. I will close this issue but feel free to resubmit in the PR format. |
@gaearon Thanks, I opened a new one facebook/react#22169 |
Sorry that’s not what I was suggesting. This is the correct repository for RFCs (not the React one!) but the RFCs need to be opened as pull requests (not issues). Please read the README which explains the process. |
Thanks, I did it #201 |
I start with an example:
Imagine we have the above code, what is a problem? problem is React runs
useEffect
inside function every timecount
changes, but might we don't need to know updated count's value untilvisibilitychange
event happens.we can have a new hook like this:
and we can change exmaple code to this:
So, we could remove
count
fromuseEffect
dependence anduseEffect
inside function just run onceAlso, this hook is very useful for
useCallback
, please see this exmaple:we can change to
useStateRef
is just a name and we can have a better name for thatThe text was updated successfully, but these errors were encountered: