mirror of
https://github.com/streamich/react-use.git
synced 2025-12-08 18:02:14 +00:00
This re-implements outside click hook functionality from scratch,
removes dependency on use-onoutsideclick package.
BREAKING CHANGE: 🧨 useOutsideClick is now useClickAway
399 B
399 B
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, () => {
alert('OUTSIDE CLICKED');
});
return (
<div ref={ref} style={{
width: 200,
height: 200,
background: 'red',
}} />
);
};