useOutsideClick
Aboutβ
Outside click(for a ref) event as hook for React.
Installationβ
npm install --save rooks
Importing the hookβ
import { useOutsideClick } from 'rooks';
Usageβ
function Demo() {
const pRef = useRef();
function outsidePClick() {
alert('Clicked outside p');
}
useOutsideClick(pRef, outsidePClick);
return (
<div>
<p ref={pRef}>Click outside me</p>
</div>
);
}
render(<Demo />);
Codesandbox Exampleβ
Basic usageβ
Join Bhargav's discord serverβ
You can click on the floating discord icon at the bottom right of the screen and talk to us in our server.