react-use/docs/useRefMounted.md
inker 381cc2d38e
Fix example
Fix typo
2019-04-22 16:32:22 +03:00

403 B

useRefMounted

Lifecycle hook that tracks if component is mounted. Returns a ref, which has a boolean .current property.

Usage

import {useRefMounted} from 'react-use';

const Demo = () => {
  const refMounted = useRefMounted();

  useEffect(() => {
    setTimeout(() => {
      if (refMounted.current) {
        // ...
      } else {
        // ...
      }
    }, 1000);
  });
};