- Hooks
- Browser hooks
- useMounted
useMounted
Determine whether the component is mounted or not.
Installation
Copy and paste the following code into your project.
use-mounted.ts
Update the import paths to match your project setup.
Usage
import { useMounted } from "@/hooks/useMounted";
function MyComponent() {
const isMounted = useMounted();
return <div>{isMounted ? "Mounted" : "Not mounted"}</div>;
}
Return value
Name | Type | Description |
---|---|---|
isMounted | boolean | true if running in a client-side environment, false otherwise. |