useMounted returns true after the component has mounted (false on first server render). This is useful to skip SSR-unsafe side effects.
Usage
Returns
boolean - Returns false on first render (server-side), then true after the component mounts on the client.
Examples
Conditional Client-Side Rendering
Avoiding Hydration Mismatches
Window API Access
Notes
- The hook returns
falseon the initial render andtrueafter the firstuseEffectruns - Useful for preventing hydration mismatches when using browser-only APIs
- Common use cases include accessing
window,localStorage, or other client-only features