# use-on-click-away

> I'ts a React custom hook that catches clicks outside of the element it is applied to.

Latest version **0.1.1** (published 2023-08-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install use-on-click-away
pnpm add use-on-click-away
yarn add use-on-click-away
bun add use-on-click-away
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2023-08-06 |
| First published | 2022-04-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | vczb |
| Maintainers | vczb |
| Keywords | react, hook, click, away |

## Links

- npm: https://www.npmjs.com/package/use-on-click-away
- Repository: https://github.com/vczb/use-on-click-away
- Homepage: https://github.com/vczb/use-on-click-away#readme
- Issues: https://github.com/vczb/use-on-click-away/issues
- npm.io page: https://npm.io/package/use-on-click-away

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

- 0.1.1 (latest) — 2023-08-06
- 0.1.0 — 2023-08-06
- 0.0.2 — 2022-04-20
- 0.0.1 — 2022-04-19

## README

# useOnClickAway

It's a `12kb` React custom hook that catches clicks outside of the element it is applied to.

## Installation

use-on-click-away is available as an [npm package](https://www.npmjs.com/package/use-on-click-away).

To install it, run:

```bash
  //with npm
  npm install use-on-click-away

  //with yarn
  yarn add use-on-click-away
```

## Example

[`use-on-click-away-demo`](https://codesandbox.io/s/use-on-click-away-demo-lk4xkk?file=/src/App.tsx)

## Usage

```js
const MyComponent = () => {
  const ref = useRef()

  useOnClickAway(ref, () => {
    console.log('clicked away')
  })

  return (
    <div ref={ref}>
      ...
    </div>
  )

}

export default MyComponent
```

# Contributing

You can contribute by opening an issue or sending a pull request.

# License

This project is licensed under the [MIT](./LICENSE) License.

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