File size: 674 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# `useMountedState`

> **NOTE!:** despite having `State` in its name **_this hook does not cause component re-render_**.  
> This component designed to be used to avoid state updates on unmounted components.

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

## Usage

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

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

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