1.0.1 • Published 3 years ago
@artifak/useclickaway v1.0.1
@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>
);
};
1.0.1
3 years ago