Installation
CLI
npx shadcn@latest add https://kelvinmai.io/r/use-mounted.json
Manual
Copy and paste the following code into your project
hooks/use-mounted.ts
'use client';import * as React from 'react';export const useMounted = () => {const [mounted, setMounted] = React.useState<boolean>(false);React.useEffect(() => {setMounted(true);}, []);return mounted;};
Update the import paths to match your project setup
Usage
import { useMount } from '@/hooks/use-mounted';const mounted = useMounted();
API Reference
Returns
The useMount
hook returns the following boolean:
Name | Type | Description |
---|---|---|
mounted | boolean | Whether or not the current component has mounted. |