@ej-hooks/use-click
React Hook to detect a click on an any React Element
Installation
yarn
yarn add @ej-hooks/use-click
npm
npm i @ej-hooks/use-click
Usage
import React from 'react';
import useClick from '@ej-hooks/use-click';
function App() {
const onClick = () => console.log('Somebody clicked!');
const makedRef = useClick(onClick);
return <h1 ref={makedRef}>Hello Hooks</h1>;
}
Arguments
Argument | Type | Description | Required |
---|---|---|---|
onClick | function | Function to be called when the element is clicked | yes |
Return
Return value | Type | Description | Default value |
---|---|---|---|
ref | React Ref | A React Ref listening to the click event, add it to any element | null |