@artifak/useclickaway
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@artifak/useclickaway

A React hook to trigger a callback when a click event occurs on a target that is not the specified ref HTML element.

Usage

import React from 'react';
import { useClickAway } from '@artifak/useclickaway;

const Dummy = () => {
    const ref: React.RefObject<HTMLDivElement> = React.createRef();

    const onClickAway = () => {
      console.log('Clicked');
    };

    useClickAway(ref, onClickAway);

    return (
      <div>
        Wrapper
        <div ref={ref}>
          Click Me
        </div>
      </div>
    );
  };

Readme

Keywords

none

Package Sidebar

Install

npm i @artifak/useclickaway

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

4.68 kB

Total Files

10

Last publish

Collaborators

  • heyjules