An open API service indexing awesome lists of open source software.

https://github.com/elforastero/use-click-outside

React hook to detect clicks outside of the components. With shadow DOM support.
https://github.com/elforastero/use-click-outside

Last synced: about 1 year ago
JSON representation

React hook to detect clicks outside of the components. With shadow DOM support.

Awesome Lists containing this project

README

          

Welcome to use-click-outside 👋




Version

> React hook to execute callback when a click is happened outside of component.

## Install

```sh
yarn add use-click-outside
```

## Usage

```jsx
import React, { useRef } from 'react';
import useClickOutside from 'use-click-outside';

const Modal = ({ onClose }) => {
const ref = useRef();
useClickOutside(ref, onClose);

return Hello, World!;
};
```

Or if you need a custom event type instead of default 'click', third parameter can be passed:

```js
useClickOutside(ref, onClose, 'mousedown');
```

## Show your support

Give a ⭐️ if this project helped you!

***
_This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_