platform-bible-react
    Preparing search index...

    Function useEventAsync

    • Adds an event handler to an asynchronously subscribing/unsubscribing event so the event handler runs when the event is emitted. Use papi.network.getNetworkEvent to use a networked event with this hook.

      Delivery is guarded per subscription: once a subscription is superseded (the event or eventHandler reference changed) or the component unmounts, an emission that still arrives from it — e.g. one already in flight over the network — is ignored rather than delivered to eventHandler. If the subscribe promise resolves only after the subscription was already superseded, the resolved unsubscriber is invoked immediately so the subscription does not leak. Subscribe and unsubscribe failures are logged rather than thrown — neither has a caller that could catch them. A failed unsubscribe is logged, not retried.

      Type Parameters

      • T

      Parameters

      • event: undefined | PlatformEvent<T> | PlatformEventAsync<T>

        The asynchronously (un)subscribing event to subscribe to.

        • If event is a PlatformEvent or PlatformEventAsync, that event will be used
        • If event is undefined, the callback will not be subscribed. Useful if the event is not yet available for example
      • eventHandler: PlatformEventHandler<T>

        The callback to run when the event is emitted

        WARNING: MUST BE STABLE - const or wrapped in useCallback. The reference must not be updated every render

      Returns void