Initial commit
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
# useMounted
|
||||
|
||||
Returns `true` after the component has mounted on the client. Useful for deferring client-only rendering to avoid SSR hydration mismatches.
|
||||
|
||||
## Signature
|
||||
|
||||
```ts
|
||||
function useMounted(): boolean;
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```tsx
|
||||
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'`).
|
||||
Reference in New Issue
Block a user