Skip to content

Latest commit

 

History

History
26 lines (20 loc) · 414 Bytes

useOutsideClick.md

File metadata and controls

26 lines (20 loc) · 414 Bytes

useOutsideClick

React UI hook that triggers a callback when user clicks outside the target element.

Usage

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',
    }} />
  );
};