tryOnScopeDispose
Commons
stable
Safely register a cleanup callback with onScopeDispose(). When called outside an active effect scope the function is ignored and returns false, preventing the "getCurrentScope is undefined" error.
API
Signature
Full TypeScript signature sourced from the util file.
API
Parameters
Input parameters accepted by this util.
- fnrequiredTFn
- The cleanup callback to register. Called when the current effect scope is disposed (e.g. component unmount).
API
Return value
The value returned by this util.
- true when the callback was successfully registered inside an active scope; false when there is no active scope and the callback was skipped.
Usage
Examples
Ready-to-paste usage snippets.
Cleanup inside and outside a scope