Skip to content

Rule · Lint

Event listener or interval added in an effect without cleanup

lint/listener-without-cleanupwarnvoid lintupdated

Why it matters

Listeners/intervals added in useEffect without removal stack up on every re-run and remount: duplicated handlers, leaked components and degraded INP over a session.

How to fix it

Return a cleanup that calls removeEventListener/clearInterval, or pass { signal } from an AbortController and abort it.

Example

tsx
useEffect(() => {
  const ac = new AbortController()
  window.addEventListener('resize', onResize, { signal: ac.signal })
  return () => ac.abort()
}, [])

References

void lint reports 67 rules in this category. Static source checks with no browser: Tailwind v4 silent failures, Next.js 16 API traps, React render-body bugs, accessibility markup, SEO files and motion hygiene.