Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

use-event-handler

A simple React Hook for listening events of HTML element

Installation

$ yarn add use-event-handler

Usage

export default () => {
  const ref = useRef<HTMLDivElement>(null);
  useEvent('click', event => console.log(event), { element: ref.current });

  return <div ref={ref} />;
};

API

useEvent(type, handler, options)

  • type*: A string of event name
  • handler*: A function that will be called whenever eventName trigger on element.
  • options: An object of { element?: Element, capture?: boolean, passive?: boolean, once?: boolean }, where element is the element to add the event listener, and others will be passed to addEvenetListener. MDN

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages