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.
- Host: GitHub
- URL: https://github.com/elforastero/use-click-outside
- Owner: ElForastero
- License: mit
- Created: 2019-09-20T09:19:49.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T09:54:17.000Z (over 3 years ago)
- Last Synced: 2025-02-27T12:08:29.534Z (over 1 year ago)
- Language: TypeScript
- Size: 684 KB
- Stars: 24
- Watchers: 1
- Forks: 1
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Welcome to use-click-outside 👋
> 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)_