|
Download react-use/docs/useClickAway.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 566 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/docs/useClickAway.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/docs/useClickAway.md
-
curl -L -o useClickAway.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/docs/useClickAway.md
566 Bytes
| # `useClickAway` | |
| React UI hook that triggers a callback when user | |
| clicks outside the target element. | |
| ## Usage | |
| ```jsx | |
| import {useClickAway} from 'react-use'; | |
| const Demo = () => { | |
| const ref = useRef(null); | |
| useClickAway(ref, () => { | |
| console.log('OUTSIDE CLICKED'); | |
| }); | |
| return ( | |
| <div ref={ref} style={{ | |
| width: 200, | |
| height: 200, | |
| background: 'red', | |
| }} /> | |
| ); | |
| }; | |
| ``` | |
| ## Reference | |
| ```js | |
| useClickAway(ref, onMouseEvent) | |
| useClickAway(ref, onMouseEvent, ['click']) | |
| useClickAway(ref, onMouseEvent, ['mousedown', 'touchstart']) | |
| ``` | |