Skip to content

Files

Latest commit

 

History

History
25 lines (19 loc) · 405 Bytes

useRefMounted.md

File metadata and controls

25 lines (19 loc) · 405 Bytes

useRefMounted

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

用法

import {useRefMounted} from 'react-use';

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

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