onDestroy: Cleanup
Run teardown logic such as clearing timers or unsubscribing when the component is removed.
Why onDestroy
onDestroy runs when a component is removed from the DOM. Use it to tear down listeners, timers, or subscriptions.
Import and Call
Import from svelte and pass a callback.
<script>
import { onDestroy } from "svelte";
onDestroy(() => console.log("bye"));
</script>