Skip to content
This repository has been archived by the owner on Aug 14, 2023. It is now read-only.

Latest commit

 

History

History

useClickAway

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

useClickAway

Demo

Hook that triggers a callback when the user clicks outside the target element.

Example

import React from 'react';
import { useClickAway } from 'react-essential-tools';

const Demo = () => {
  const ref = useRef(null);

  useClickAway(ref, () => {
    console.log('clicked');
  });

  return (
    <div ref={ref} style={{
      width: 200,
      height: 200,
      background: 'red',
    }} />
  );
};