useClickAway

当用户在目标元素外部单击时,React UI 钩子触发回调。

Usage

  1. import {useClickAway} from 'react-use';
  2. const Demo = () => {
  3. const ref = useRef(null);
  4. useClickAway(ref, () => {
  5. alert('OUTSIDE CLICKED');
  6. });
  7. return (
  8. <div ref={ref} style={{
  9. width: 200,
  10. height: 200,
  11. background: 'red',
  12. }} />
  13. );
  14. };