Skip to content

Code

React effect subscribes but never cleans upcode.effect-without-cleanup

This useEffect adds a listener, starts an interval or opens a subscription, but returns no cleanup function. Every re-render or page visit adds another one: memory grows, handlers fire many times, and realtime/database listeners keep running (and billing) after the component is gone.

  • In force Rule code.effect-without-cleanup
  • 3 clauses

At a glance

code.effect-without-cleanup
Severitymedium
CertaintyObserved — the code as written is the problem
Looks atyour source code
When it runsRuns on every scan

How to fix it

Return a cleanup: `useEffect(() => { const id = setInterval(tick, 1000); return () => clearInterval(id) }, [])`, `return () => window.removeEventListener("resize", onResize)`, `return () => unsubscribe()`.

Check your own app

Run npx scanlyfix scan in your project. Every finding gets an id; after fixing, npx scanlyfix verify <id> proves it is gone.

If it is a false positive in your project, silence that one line with // scanlyfix-ignore-next-line code.effect-without-cleanup -- <why>.

All rules

Your code stays
on your machine

Only findings are uploaded, and only to your own dashboard.