这是indexloc提供的服务,不要输入任何密码
Skip to content

utsuboco/events

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@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
}

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •