Function: useCastState()
function useCastState(): CastConnectionState;
Defined in: packages/cast/src/use-cast-state.ts:41
The live cast connection state, as renderable React state.
This is the one subscription every cast-aware screen needs: it decides whether to draw a cast affordance at all, whether to show a "connecting…" spinner, and whether the transport controls are steering the phone or a receiver.
Seeded synchronously, so the first paint is already right rather than
flashing through 'unavailable': the initial value is a direct
Cast.getCastState() read, and the effect re-reads once on subscribe
because Cast.initialize() may have resolved between that render and the
effect running.
No timer, no polling — the castState event is the only thing that moves
this, and the subscription is torn down on unmount. Several components may
call it; each holds its own listener, which is a Set insertion on the
shared singleton.
Returns
One of the five CastConnectionState values.
'unavailable' is the honest answer both before Cast.initialize()
resolves and forever on a device without Google Play services — it is not
an error state, and <CastButton/> treats it as "draw nothing".
Example
import { useCastState } from '@afkcodes/timbre-cast'
function CastStatus() {
const state = useCastState()
if (state === 'unavailable') return null
return <Text>{state === 'connected' ? 'Casting' : state}</Text>
}