|
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/main/react-use/docs/useClickAway.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-use/docs/useClickAway.md
-
curl -L -o useClickAway.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useClickAway.md
566 Bytes
useClickAway
React UI hook that triggers a callback when user clicks outside the target element.
Usage
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
useClickAway(ref, onMouseEvent)
useClickAway(ref, onMouseEvent, ['click'])
useClickAway(ref, onMouseEvent, ['mousedown', 'touchstart'])