Skip to main content

useIsMounted

Importing useIsMounted Hook​

import { useIsMounted } from '@ciceksepeti/cui-hooks';

Example​

import React, { useEffect, useState } from 'react';
import { useIsMounted } from '@ciceksepeti/cui-hooks';

export const IsMounted = () => {
const [text, setText] = useState('');
const isMounted = useIsMounted();

useEffect(() => {
if (isMounted()) setText('Mounted');
else setText('Not mounted');
}, [isMounted]);

return <div>{text}</div>;
};

Preview​

PREVIEW
useIsMounted
  • Returns a memoized callback function to retrieve isMounted boolean value.
  • Returns true if mounted, otherwise false
RESULT: