@utsubo/events
TypeScript icon, indicating that this package has built-in type declarations

0.1.7 • Public • Published

@utsubo/events

Minimalist library to emit and receive custom events.

yarn add @utsubo/events

Example

import { onEvent, offEvent, emitEvent, useEvent } from '@utsubo/events'

// Create an event listener
const handler = (e) => console.log('event', e)
onEvent('event', handler, { once: false })

// Dispatch a payload to event listeners
emitEvent('event', 'event data')

// Remove the event listener
offEvent('event', handler, { once: false })

// React hook bindings to create reactive handlers.
function Component() {
  useEvent('event', (e) => console.log('event', e), [key], { once: false })
}

Readme

Keywords

Package Sidebar

Install

npm i @utsubo/events

Weekly Downloads

11,352

Version

0.1.7

License

MIT

Unpacked Size

9.91 kB

Total Files

19

Last publish

Collaborators

  • onirenaud