JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 24336
  • Score
    100M100P100Q141969F
  • License MIT

react library for custom events

Package Exports

  • @utsubo/events

Readme

@utsubo/events

yarn add @utsubo/events

Minimalist library to emit and receive custom events. useEvent will automatically attach events when mounted and detach them when unmounted.

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

emitEvent('hello', 5)

const vanillaFunc = (payload) => { console.log(payload) } // = 5

onEvent('hello', vanillaFunc, {once: false})
// detach event
offEvent('hello', vanillaFunc)


const DummyComponent = () => {
  // automatically attached on mount and detached on unmount
  useEvent('hello', (payload) => {
    // payload = 5
  }, {once: false})

  return null
}