useMounted

A hook that returns true if the component has mounted. Useful for SSR hydration.

Installation

CLI

Usage

useMounted returnstrue after the component has mounted. Its primarily useful to avoid SSR hydration mismatches when you need to access browser-only APIs.

mounted: false
This flips to true after the component mounts.

Examples

Avoid hydration mismatch

Guard browser-only reads (like localStorage) until after mount.

See code tab

API Reference

This hook has no props. It returns a boolean.

Source Code