# outside-click-handler

> Outside click handler for React

Latest version **1.0.8** (published 2018-05-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install outside-click-handler
pnpm add outside-click-handler
yarn add outside-click-handler
bun add outside-click-handler
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2018-05-03 |
| First published | 2018-01-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 187.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Stanislav Botev |
| Maintainers | yozhikm |
| Keywords | react, outside |

## Links

- npm: https://www.npmjs.com/package/outside-click-handler
- npm.io page: https://npm.io/package/outside-click-handler

## 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.8 (latest) — 2018-05-03
- 1.0.7 — 2018-03-27
- 1.0.6 — 2018-01-23
- 1.0.5 — 2018-01-13
- 1.0.4 — 2018-01-09
- 1.0.3 — 2018-01-09
- 1.0.2 — 2018-01-09
- 1.0.1 — 2018-01-09
- 1.0.0 — 2018-01-09

## README

# OutsideClickHandler

[![Greenkeeper badge](https://badges.greenkeeper.io/YozhikM/outside-click-handler.svg)](https://greenkeeper.io/)
[![npm](https://img.shields.io/npm/dt/outside-click-handler.svg)](http://www.npmtrends.com/outside-click-handler)
![FlowType compatible](https://img.shields.io/badge/flowtype-compatible-brightgreen.svg)

This component is designed to handle all clicks outside, for example, to open and close modal windows.

## Features

- Easy to use
- Tests covered
- Flowtype definitions
- Lightweight (2.8kb gzip)

## API

The component accepts two types of props: children and callback function.
At `componentDidMount()` adds the listener, who is waiting for the click event, and `componentWillUnmount()` is removed.

````js
type Props = {
  children: React.Node,
  onOutsideClick: Function,
};
````

## How to use

````js
class Wrapper extends React.Component {
  onClick = () => this.setState({ isShownHidden: !this.state.isShownHidden });

  render() {
    const { isShownHidden } = this.state;
    return (
      <OutsideClickHandler onOutsideClick={this.onClick}>
        <span>Im your child!</span>
        {isShownHidden && <span>Im your hidden child!</span>}
      </OutsideClickHandler>
    );
  }
}
````

## Performance

If you want to use a component in lists, use conditions or methods to avoid poor performance.


## Support

If you have any questions, please email me at botev.st@gmail.com or open the issue.

To use static typing, make sure [that you have installed Flow](https://flow.org/en/docs/install).

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