Skip to content

Files

Latest commit

61b0355 Β· Aug 19, 2019

History

History
28 lines (21 loc) Β· 479 Bytes

useRefMounted.md

File metadata and controls

28 lines (21 loc) Β· 479 Bytes

useRefMounted

DEPRECATED
This method is obsolete, use useMountedState instead.

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);
  });
};