@jsvision/ui / onCleanup
Function: onCleanup()
onCleanup(
cb):void
Defined in: ui/src/reactive/owner.ts:141
Register a teardown callback that runs when the surrounding reactive lifetime ends. Called inside an effect/computed body, it fires before each re-run and once at disposal (use it to release what that run acquired — a timer, a subscription). Called directly inside a scope, it fires once when the scope is disposed. Called outside any computation and any scope it can never run, so it is a no-op with a dev warning.
Parameters
cb
() => void
The teardown callback.
Returns
void
Example
ts
import { createRoot, signal, effect, onCleanup } from '@jsvision/ui';
createRoot((dispose) => {
const ms = signal(1000);
effect(() => {
const id = setInterval(tick, ms());
onCleanup(() => clearInterval(id)); // clears before each re-run and at dispose()
});
dispose(); // fires the pending cleanup → clearInterval
});