Package Exports
- @utsubo/events
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 (@utsubo/events) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@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
}