/ hooks / useCommandQueue.ts
useCommandQueue.ts
 1  import { useSyncExternalStore } from 'react'
 2  import type { QueuedCommand } from '../types/textInputTypes.js'
 3  import {
 4    getCommandQueueSnapshot,
 5    subscribeToCommandQueue,
 6  } from '../utils/messageQueueManager.js'
 7  
 8  /**
 9   * React hook to subscribe to the unified command queue.
10   * Returns a frozen array that only changes reference on mutation.
11   * Components re-render only when the queue changes.
12   */
13  export function useCommandQueue(): readonly QueuedCommand[] {
14    return useSyncExternalStore(subscribeToCommandQueue, getCommandQueueSnapshot)
15  }