useWhenMounted
Execute a callback and expose its return value as a reactive Observable<T | undefined> — only after the component has mounted. Returns undefined during SSR and before hydration, then re-evaluates with the actual callback value once mounted. Unlike useSupported, the return value is not coerced to boolean — the full type T is preserved.
import { useWhenMounted } from "@usels/web";
const windowWidth = useWhenMounted(() => window.innerWidth);
// undefined on the server, actual width after mountconsole.log(windowWidth.get());Deferred browser API access
Section titled “Deferred browser API access”import { useWhenMounted } from "@usels/web";
const scrollY = useWhenMounted(() => window.scrollY);Type Declarations
Section titled “Type Declarations”export type UseWhenMountedReturn<T> = Observable<T | undefined>;export declare function useWhenMounted<T>(callback: () => T): UseWhenMountedReturn<T>;Source
Section titled “Source”Contributors
Section titled “Contributors”- tigerwest
Changelog
Section titled “Changelog”a7392ab2026-03-06 - feat(core,browser): add sync strategy hooks (tigerwest)