tryOnMounted
Run fn after mount when called during a component's setup; immediately otherwise (standalone scopes, tests, plain scripts). Cross-platform — import from @sigx/use.
import { tryOnMounted } from '@sigx/use';
tryOnMounted(() => {
// inside a component: runs after mount
// standalone: runs right now
measure();
});
Web composables use this to defer environment reads (storage, layout) to the client-mounted moment without failing outside components — so the same code works in a component, an effectScope(), or a bare script.
Signature
function tryOnMounted(fn: () => void): void;
Platform: everywhere.
See also
tryOnScopeDispose— the teardown counterpart.- Conventions → Lifecycle helpers — how these two power the cleanup model.
- Conventions — the shared input/output patterns.
