useEventListenerRef
Aboutβ
A react hook to add an event listener to a ref
Installationβ
npm install --save rooks
Importing the hookβ
import { useEventListenerRef } from 'rooks';
Usageβ
function Demo() {
const ref = useEventListenerRef('click', function () {
console.log('clicked');
});
return <div ref={ref}>Click me</div>;
}
render(<Demo />);
Codesandbox Examplesβ
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.