Skip to content

WillMayger/use-event

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

useEvent React Hook

This replaces the need for using window.addEventListener() when using react hooks.

You use it in exactly the same way as window.addEventListener().

Install

Yarn: yarn add use-add-event

NPM: npm install --save use-add-event

Usage

useEvent(event, handler, useCapture)

event: STRING - any event listener event as a string. handler: FUNCTION - function to be called when the event is triggered. useCapture: BOOL - determining passive event or not (defaults to false).

Example:

import useEvent from 'use-add-event';

export default function MyComponent() {
  const handleResize = (e) => { ... };
  useEvent('resize', handleResize);
  return (
    ...
  )
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published