Skip to content

sarkis1231/use-click-outside

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

React hook to execute callback when a click is happened outside of html element.

Install

yarn add use-click-outside-close

Usage

import React, { useRef } from 'react';
import useClickOutside from 'use-click-outside';

const Modal = ({ onClose }) => {
  const ref = useRef();
  useClickOutside(ref, onClose);

  return <div ref={ref}>Hello, World!</div>;
};

Or if you need a custom event type instead of default 'click', third parameter can be passed:

  useClickOutside(ref, handler);

Show your support

Give a ⭐️ if this project helped you!

About

React hook to execute a callback when a click is happened outside of the HTML element.

Resources

License

Stars

Watchers

Forks

Packages

No packages published