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.

TypeScript
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#

TypeScript
function tryOnMounted(fn: () => void): void;

Platform: everywhere.

See also#