@cartridge-engine/event
    Preparing search index...

    Function useSubscribe

    • Subscribe to an event and automatically unsubscribe on unmount.

      The subscription is re-bound whenever an entry in deps changes, allowing the callback to close over fresh state without a callback-ref wrapper. Pass the same values you would put in a useEffect dependency array.

      Parameters

      • event: string

        The event name to subscribe to.

      • callback: (payload: any) => void

        The callback to invoke when the event is emitted.

      • deps: any[] = []

        Optional dependency array (default []). When any dep changes, the subscription is re-bound with the latest callback.

      Returns void

      const [count, setCount] = useState(0);
      useSubscribe('increment', () => setCount(c => c + 1), []);