1.0.0 • Published 3 years ago

@ej-hooks/use-click v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@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

ArgumentTypeDescriptionRequired
onClickfunctionFunction to be called when the element is clickedyes

Return

Return valueTypeDescriptionDefault value
refReact RefA React Ref listening to the click event, add it to any elementnull