react-use/docs/useOutsideClick.md
2019-03-23 15:28:45 -04:00

33 lines
517 B
Markdown

# `useOutsideClick`
React UI hook that triggers a callback when user
clicks outside the target element.
Requires `use-onclickoutside`:
```bash
npm add use-onclickoutside
# or
yarn add use-onclickoutside
```
## Usage
```jsx
import {useOutsideClick} from 'react-use';
const Demo = () => {
const ref = useRef(null);
useOutsideClick(ref, () => {
console.log('OUTSIDE CLICKED');
});
return (
<div ref={ref} style={{
width: 200,
height: 200,
background: 'red',
}} />
);
};
```