# simple-react-clickaway

> Simple react hook to listen click away

Latest version **1.0.6** (published 2021-05-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install simple-react-clickaway
pnpm add simple-react-clickaway
yarn add simple-react-clickaway
bun add simple-react-clickaway
```

## 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.0.6 |
| Published | 2021-05-26 |
| First published | 2021-05-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | vivedevelopment |
| Maintainers | vivedevelopment |
| Keywords | react, clickaway |

## Links

- npm: https://www.npmjs.com/package/simple-react-clickaway
- Repository: https://github.com/ViveDevelopment/simple-react-clickaway
- Issues: https://github.com/ViveDevelopment/simple-react-clickaway
- npm.io page: https://npm.io/package/simple-react-clickaway

## 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.0.6 (latest) — 2021-05-26
- 1.0.5 — 2021-05-25
- 1.0.4 — 2021-05-25
- 1.0.3 — 2021-05-25
- 1.0.2 — 2021-05-25
- 1.0.0 — 2021-05-25

## README

# Simple React Clickaway Hook

Simple react `useClickAway` hook, which listens for clicks outside the element.

## Installation

```
npm i simple-react-clickaway
```

Import hook

```js
import {useClickAway} from 'simple-react-clickaway';
```

And use it like:

```js
const {disable, enable} = useClickAway(ref, onClickAway);
```

## Example

Here is a simple example of detecting a click outside a modal window:

```js
import "./styles.css";
import { useClickAway } from "simple-react-clickaway";
import { useRef } from "react";

export default function App() {
  const modalRef = useRef();
  const handleClickAway = () => {
    alert("You clicked away!");
  };
  const { disable, enable } = useClickAway(modalRef, handleClickAway);
  return (
    <div className="App">
      <div className="modal" ref={modalRef}>
        <button onClick={disable}>Disable click away</button>
        <button onClick={enable}>Enable click away</button>
      </div>
    </div>
  );
}
```
[View it on a code sandbox](https://codesandbox.io/s/simple-react-clickaway-qduck)

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