React hook that connects to a WebSocket subscription and provides reactive state.
A function that creates a Subscription handle (e.g. () => client.live.events()).
() => client.live.events()
Hook options (enabled, maxEvents).
Reactive subscription state: lastEvent, events, state, send, close.
lastEvent
events
state
send
close
function LiveFeed() { const { events, state, send } = useSubscription( () => client.live.events(), { maxEvents: 100 } ); return ( <div> <p>Status: {state}</p> {events.map((e, i) => <div key={i}>{e.message}</div>)} <button onClick={() => send({ text: 'hello' })}>Send</button> </div> );} Copy
function LiveFeed() { const { events, state, send } = useSubscription( () => client.live.events(), { maxEvents: 100 } ); return ( <div> <p>Status: {state}</p> {events.map((e, i) => <div key={i}>{e.message}</div>)} <button onClick={() => send({ text: 'hello' })}>Send</button> </div> );}
React hook that connects to a WebSocket subscription and provides reactive state.