Skip to content

Latest commit

 

History

History
34 lines (24 loc) · 674 Bytes

useClickOutside.md

File metadata and controls

34 lines (24 loc) · 674 Bytes

useClickOutside

Detect clicks outside of a specified element.

Usage

import React from "react";
import { useClickOutside } from "react-hooks-pack";
import { useClickOutside } from "react-hooks-pack/esm"; //ES6 modules

const log = () => console.log("Clicked");

function Example() {
  const ref = useClickOutside<HTMLDivElement>(log);

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

Reference

import { useClickOutside } from "react-hooks-pack";
import { useClickOutside } from "react-hooks-pack/esm"; //ES6 modules

const ref = useClickOutside(fn);
  • ref: RefObject<T extends HTMLElement> — Ref