tryOnScopeDispose#

Register teardown with the currently-active scope — the owning component's setup, or the innermost running effectScope(). Cross-platform — import from @sigx/use.

TypeScript
import { tryOnScopeDispose } from '@sigx/use';

const id = setInterval(tick, 1000);
tryOnScopeDispose(() => clearInterval(id));

It returns false (retaining nothing) when called outside any scope — the caller keeps responsibility for disposal then. That's exactly why every composable with ongoing work also returns an explicit stop()/Pausable handle: it's the escape hatch for standalone, scope-less use.

TypeScript
const registered = tryOnScopeDispose(cleanup);
if (!registered) {
    // no active scope — you must call cleanup() yourself
}

Signature#

TypeScript
function tryOnScopeDispose(fn: () => void): boolean;

Returns true when the teardown was registered with a scope, false when there was no active scope.

Platform: everywhere.

See also#