Skip to content

Latest commit

 

History

History
25 lines (20 loc) · 484 Bytes

useMountedState.md

File metadata and controls

25 lines (20 loc) · 484 Bytes

useMountedState

Lifecycle hook providing ability to check component's mount state.
Gives a function that will return true if component mounted and false otherwise.

Usage

import * as React from 'react';
import {useMountedState} from 'react-use';

const Demo = () => {
  const isMounted = useMountedState();

  React.useEffect(() => {
    setTimeout(() => {
      if (isMounted()) {
        // ...
      } else {
        // ...
      }
    }, 1000);
  });
};