onCleanup()
Register a function that runs when the component unmounts.
Signature
Section titled “Signature”function onCleanup(fn: () => void): voidParameters
Section titled “Parameters”| Param | Type | Description |
|---|---|---|
fn | () => void | Cleanup function |
Examples
Section titled “Examples”import { component, onCleanup, div } from "@whisq/core";
const Sub = component(() => { const sub = eventBus.subscribe(handler); onCleanup(() => sub.unsubscribe()); return div("Listening");});