React hooks for subscribing to NATS subjects via the shared connection provided by ``, with support for both raw byte messages and JSON-decoded payloads. ## Key Components ### `useNatsSubscription` Core hook that subscribes to a NATS subject using the shared connection from ``. Automatically resubscribes when the subject changes, the connection becomes ready, or a reconnection occurs. **Parameters:** - `subject` — NATS subject string, or `null` to disable - `onMessage` — callback receiving raw `Msg` objects - `options` — optional `NatsSubscribeOptions` plus `enabled` flag **Returns:** `{ isSubscribed, isReady }` ### `useNatsJsonSubscription` Convenience wrapper around `useNatsSubscription` that automatically decodes incoming message bytes as JSON and passes the parsed payload to the callback. Malformed payloads are silently ignored. **Parameters:** - `subject` — NATS subject string, or `null` to disable - `onPayload` — callback receiving `(payload: T, msg: Msg)` - `options` — same options as `useNatsSubscription` ### `UseNatsSubscriptionOptions` Extends `NatsSubscribeOptions` with an `enabled?: boolean` flag to conditionally pause subscriptions without unmounting the component. ## Usage Example ```typescript // Raw byte subscription function MyComponent() { const { isSubscribed } = useNatsSubscription( 'events.updates', (msg) => console.log('raw bytes:', msg.data), { queue: 'workers', enabled: true }, ) return {isSubscribed ? 'Listening' : 'Disconnected'} } // JSON subscription with typed payload interface TickerEvent { symbol: string price: number } function TickerDisplay() { const { isReady } = useNatsJsonSubscription( 'market.ticker', (payload, msg) => { console.log(`${payload.symbol}: $${payload.price}`) }, ) } ``` > Both hooks stabilize the message handler via `useRef` so the subscription is not torn down on every render when an inline callback is passed.