@artifak/useclickaway
v1.0.1
Published
A hook to handle click events when not occurring on targeted element.
Downloads
5
Readme
@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>
);
};