Evit packages documentation
    Preparing search index...

    Function useEventEffect

    • 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.

      Type Parameters

      • const T extends Action<any, any> | readonly [Action<any, any>, Action<any, any>]

      Parameters

      • event: T

        A single event or an array of events to listen to.

      • handler: (...args: InferParameters<T>) => void

        A callback that receives payload and tag as the first and second parameter.

      Returns void

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