andreoav / click-outside-hook

A simple react hook to detect click or touch events outside an element.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

click-outside-hook

A simple react hook to detect click or touch events outside an element and execute a provided callback when this happens.

NPM CircleCI Greenkeeper badge module formats: cjs, and es

Install

yarn add click-outside-hook

Usage

import React from 'react';
import useClickOutside from 'click-outside-hook';

export default function SomeAwesomeComponent() {
  const ref = useClickOutside(() => console.log('my callback'));

  return (
    <div>
      <div ref={ref}>Awesome content</div>
    </div>
  );
}

When the user clicks or touches outside the Awesome content element, the callback is executed.

License

MIT © andreoav

About

A simple react hook to detect click or touch events outside an element.

License:MIT License


Languages

Language:TypeScript 100.0%