# is-mounted-hook

> React hook for checking if the component is mounted

Latest version **1.2.0** (published 2022-10-03) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2022-10-03 |
| First published | 2022-09-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 0 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Martik Avagyan |
| Maintainers | m-avagyan |
| Keywords | react, component, mount, unmount, hook, javascript, easy-to-use, library, package, npm, yarn |

## Links

- npm: https://www.npmjs.com/package/is-mounted-hook
- Repository: https://github.com/m-avagyan/is-mounted-hook
- Homepage: https://github.com/m-avagyan/is-mounted-hook#readme
- Issues: https://github.com/m-avagyan/is-mounted-hook/issues
- npm.io page: https://npm.io/package/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.2.0 (latest) — 2022-10-03
- 1.1.1 — 2022-09-19
- 1.1.0 — 2022-09-19
- 1.0.0 — 2022-09-12
- 0.0.5 — 2022-09-12
- 0.0.4 — 2022-09-12
- 0.0.3 — 2022-09-12
- 0.0.2 — 2022-09-12
- 0.0.1 — 2022-09-12

## README

## is-mounted-hook

**React hook for checking if the component is mounted.**

**Author**

- name: _Martik Avagyan_
- email: _<martikavagyan1@gmail.com>_
- github: _[m-avagyan](https://github.com/m-avagyan)_

## Getting started

**Installation**

`npm install is-mounted-hook` or `yarn add is-mounted-hook`

**Example**

```javascript
import React, { useState, useEffect } from 'react';
import useIsMounted from 'is-mounted-hook';

import { getCars } from '../../services/cars';

import Loader from '../loader/Loader';
import Error from '../error/Error';
import CarList from '../car-list/CarList';

function Example() {
  const [isLoading, setIsLoading] = useState(true);
  const [error, setError] = useState('');
  const [data, setData] = useState(null);

  const isMounted = useIsMounted();

  useEffect(() => {
    getCars()
      .catch((error) => setError(error.message))
      .then((data) => {
        if (!isMounted.current) {
          return;
        }

        setData(data);
      })
      .finally(() => setIsLoading(false));
  }, []);

  return isLoading ? (
    <Loader />
  ) : error ? (
    <Error message={error} />
  ) : (
    <CarList data={data} />
  );
}

export default Example;
```

---

**Copyright (c) 2022 [Martik Avagyan](https://github.com/m-avagyan)**

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