Skip to content
On this page

useEventEmitter

Sometimes it is difficult to pass events between multiple components. By using EventEmitter, this can be simplified.

To get an instance of EventEmitter, you can call useEventEmitter in React components.

If the component renders multiple times, the return value of useEventEmitter in every render process will stay unchanged and no extra EventEmitter instance will be created.

You can also create instances of the global sharing.

Code demonstration

API

const event = useEventEmitter<T>()
const event = useEventEmitter<T>()

Params

PropertyDescriptionTypeDefault
globalIs it globalbooleanfalse

Result

PropertyDescriptionType
emitSend an event notification(eventName?:string,val: T) => void
useSubscriptionSubscribe to the event(eventName?:string,callback: (val: T) => void) => void

Source

SourceDocsDemo