Package Exports
- use-add-event
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (use-add-event) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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 (
...
)
}