Function: onDestroy()
Imported from
@react-logic/dionDestroy(
fn):void
Defined in: di/src/lib/lifecycle.ts:27
Register a callback to run when the surrounding construction scope is torn down. Must be called synchronously during a logic class or service constructor (or as a field initializer). Throws otherwise.
For logic classes, the callback fires when the consuming component
unmounts. For services constructed via DI, it fires when the providing
<Injector> unmounts.
Parameters
fn
() => void
Returns
void
Example
class TimeService {
timer = state<ReturnType<typeof setInterval> | null>(null);
constructor() {
onDestroy(() => {
const t = this.timer();
if (t) clearInterval(t);
});
}
}