mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
27 lines
414 B
Markdown
27 lines
414 B
Markdown
# `useOutsideClick`
|
|
|
|
React UI hook that triggers a callback when user
|
|
clicks outside the target element.
|
|
|
|
|
|
## 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',
|
|
}} />
|
|
);
|
|
};
|
|
```
|