Arc.React
    Preparing search index...

    Function useOnMessage

    • Subscribes to messages of type TMessage from the nearest MessengerScope (or the Arc root messenger) for the lifetime of the calling component. The subscription is automatically cleaned up on unmount.

      The callback does not need to be wrapped in useCallback — a ref is used internally so stale-closure issues are avoided without forcing the caller to memoize.

      Type Parameters

      • TMessage extends object

      Parameters

      • type: Constructor<TMessage>

        Constructor of the message type to subscribe to.

      • callback: (message: TMessage) => void

        Invoked whenever a matching message is published and the filter (if any) accepts it.

      • Optionalfilter: (message: TMessage) => boolean

        Optional predicate invoked with the actual typed message; only when it returns true will callback be invoked. Useful for narrowing on message content without re-subscribing.

      Returns void