React hook to subscribe to one or more events and execute a handler when any of them fires.
The handler receives a payload as the first argument and a tag as the second one.
A single event or an array of events to listen to.
A callback that receives payload and tag as the first and second parameter.
const userCreated = defineEvent('user.created', withPayload<number>())const userDeleted = defineEvent('user.deleted', withPayload<boolean>())useEventEffect([userCreated, userDeleted], (payload, tag) => { if (tag === userCreated.tag) { console.log('Created:', payload) }}) Copy
const userCreated = defineEvent('user.created', withPayload<number>())const userDeleted = defineEvent('user.deleted', withPayload<boolean>())useEventEffect([userCreated, userDeleted], (payload, tag) => { if (tag === userCreated.tag) { console.log('Created:', payload) }})
React hook to subscribe to one or more events and execute a handler when any of them fires.
The handler receives a payload as the first argument and a tag as the second one.