Rules
no-leaked-timeout
Full Name in eslint-plugin-react-web-api
Full Name in @eslint-react/eslint-plugin
Features
🔍
Presets
web-api
recommended
recommended-typescript
recommended-type-checked
What it does
Enforces that every setTimeout
in a component or custom Hook has a corresponding clearTimeout
.
Scheduling a timeout within the setup function of useEffect
without canceling it in the cleanup function can lead to unwanted setTimeout
callback executions and may also result in using stale values captured by previous render's effects after each subsequent re-render.
Examples
Failing
Passing
Implementation
Further Reading
See Also
- no-leaked-interval
Enforces that everysetInterval
in a component or custom Hook has a correspondingclearInterval
.