# react-is-mounted-hook

> React hook to check if the component is still mounted

Latest version **1.1.2** (published 2021-07-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-is-mounted-hook
pnpm add react-is-mounted-hook
yarn add react-is-mounted-hook
bun add react-is-mounted-hook
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2021-07-05 |
| First published | 2019-06-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Maintainers | hupe1980 |
| Keywords | react, hook, component, mounted |

## Links

- npm: https://www.npmjs.com/package/react-is-mounted-hook
- Repository: https://github.com/hupe1980/react-is-mounted-hook
- Homepage: https://github.com/hupe1980/react-is-mounted-hook#readme
- Issues: https://github.com/hupe1980/react-is-mounted-hook/issues
- npm.io page: https://npm.io/package/react-is-mounted-hook

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2021-07-05
- 1.1.1 — 2021-04-29
- 1.1.0 — 2021-03-31
- 1.0.3 — 2019-11-27
- 1.0.2 — 2019-07-21
- 1.0.1 — 2019-06-01
- 1.0.0 — 2019-06-01

## README

# react-is-mounted-hook

> React hook to check if the component is still mounted

## Install

```sh
// with npm
npm install react-is-mounted-hook

// with yarn
yarn add react-is-mounted-hook
```

## How to use

```javascript
import React, { useState, useEffect } from 'react';
import useIsMounted from 'react-is-mounted-hook';
import axios from 'axios';
import Loading from './loading';
import Result from './result';

const FetchComponent = () => {
  const isMounted = useIsMounted();
  const [data, setData] = useState(null);

  useEffect(() => {
    const fetchData = async () => {
      const result = await axios(
        'http://hn.algolia.com/api/v1/search?query=redux'
      );
      if (isMounted()) {
        setData(result.data);
      }
    };

    fetchData();
  }, [isMounted]);

  return data ? <Result data={data} /> : <Loading />;
};

export default FetchComponent;
```

## License

[MIT](LICENSE)

---
_Source: https://npm.io/package/react-is-mounted-hook · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
