Skip to content
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

[Typo]: "A stopwatch" example for useRef does not cleanup correctly #7255

Open
jacobgmathew opened this issue Oct 26, 2024 · 1 comment · May be fixed by #7259
Open

[Typo]: "A stopwatch" example for useRef does not cleanup correctly #7255

jacobgmathew opened this issue Oct 26, 2024 · 1 comment · May be fixed by #7259

Comments

@jacobgmathew
Copy link

Summary

In "A stopwatch" example for useRef an interval is set in handleStart(). It is cleared in handleStop(). But if the component is unmounted after the interval is started, but without stopping it, it is never cleared, which means setNow can get called on an unmounted component.

Page

https://react.dev/reference/react/useRef#examples-value

Details

No response

@sachanritik1
Copy link

sachanritik1 commented Oct 27, 2024

adding this useEffect(() => { return () => handleStop() },[]) should do it.

I have opened a PR.

@sachanritik1 sachanritik1 linked a pull request Oct 27, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants