# react-use-mounted

> React hook for checking if the component is mounted.

Latest version **2.0.0** (published 2022-05-05) · 0 weekly downloads

## Install

```sh
npm install react-use-mounted
pnpm add react-use-mounted
yarn add react-use-mounted
bun add react-use-mounted
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2022-05-05 |
| First published | 2019-06-19 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | fabiospampinato |
| Keywords | react, hook, mounted |

## Links

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

## 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

- 2.0.0 (latest) — 2022-05-05
- 1.0.0 — 2019-06-19

## README

# React - useMounted

React hook for checking if the component is mounted.

## Install

```sh
npm install --save react-use-mounted
```

## Usage

```ts
import {useState} from 'react';
import useMounted from 'react-use-mounted';

function MyComponent () {

  const [foo, setFoo] = useState ( false );
  const mounted = useMounted ();

  useWhatever ( () => {
    if ( !mounted.current ) return; // Not mounted, avoiding calling `setFoo`
    setFoo ( true );
  });

}
```

## License

MIT © Fabio Spampinato

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