Skip to main content
Version: 5.6.0

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.