React·Intermediate·Conceptual·1 min read
When does cleanup run?
Short interview answer
Cleanup runs before an effect is set up again with changed dependencies and when the component unmounts. In development Strict Mode, React may run an extra setup-cleanup cycle to reveal missing cleanup and non-idempotent synchronization.
Key takeaway
Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.