use-click-outside
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

Welcome to use-click-outside 👋

Version

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

Install

yarn add use-click-outside

Usage

import React, { useRef } from 'react';
import useClickOutside from 'use-click-outside';
 
const Modal = ({ onClose }) => {
  const ref = useRef();
  useClickOutside(ref, onClose);
 
  return <dialog ref={ref}>Hello, World!</dialog>;
};

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

  useClickOutside(ref, onClose, 'mousedown');

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by readme-md-generator

Readme

Keywords

none

Package Sidebar

Install

npm i use-click-outside

Weekly Downloads

680

Version

2.0.0

License

MIT

Unpacked Size

10.8 kB

Total Files

13

Last publish

Collaborators

  • elforastero