Files
admin/packages/hooks/src/useMounted/Readme.md
T
2026-06-25 15:53:49 +03:00

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 false on the first render (SSR and initial client render), then true after useEffect fires.
  • Client-only ('use client').