Skip to main content

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

🔗 View source code


Interface

typescript
const useIsMounted: () => boolean

Returns

NameTypeDescription
isMountedbooleantrue 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