useIsMounted
A custom hook that provides a state value indicating whether the component is mounted.
It can be used in SSR environments to guarantee that the component has actually been mounted in the browser. (Feat. Hydration Error)
Code
Interface
typescript
const useIsMounted: () => boolean
Returns
| Name | Type | Description |
|---|---|---|
isMounted | boolean | true after the component has mounted, false before mount |
Usage
typescript
import { useIsMounted } from '@modern-kit/react';
const Example = () => {
const isMounted = useIsMounted();
return <div>{isMounted ? 'done' : 'in progress'}</div>;
};
Example
in progress