560 B
560 B
useMounted
Returns true after the component has mounted on the client. Useful for deferring client-only rendering to avoid SSR hydration mismatches.
Signature
function useMounted(): boolean;
Usage
function ThemeToggle() {
const mounted = useMounted();
if (!mounted) return null; // avoid SSR/hydration mismatch
return <button>{getCurrentTheme()}</button>;
}
Notes
- Always returns
falseon the first render (SSR and initial client render), thentrueafteruseEffectfires. - Client-only (
'use client').