useWorkoutSession
Call Signature
Section titled “Call Signature”useWorkoutSession():
WorkoutSessionSnapshot
Defined in: console-sdk/src/react/hooks/useWorkoutSession.ts:83
Reads the whole WorkoutSessionSnapshot of the provider’s one workout
session (SDK_PLAN.md §3.7 row 15, first overload). This is the exhaustive
phase union a workout screen switches over; before any start() (or after
dismiss()) it is { phase: 'idle' }. The returned object is referentially
stable across renders until the session state changes.
Returns
Section titled “Returns”the current WorkoutSessionSnapshot.
Example
Section titled “Example”const session = useWorkoutSession();switch (session.phase) { case 'idle': return <Redirect to="Setup" />; case 'running': return <RunningView progress={session.progress} />; case 'completed': return <SummaryCard result={session.result} />; // …the compiler enforces every phase is handled.}Call Signature
Section titled “Call Signature”useWorkoutSession<
T>(selector,isEqual?):T
Defined in: console-sdk/src/react/hooks/useWorkoutSession.ts:115
Reads a selected value from the WorkoutSessionSnapshot (SDK_PLAN.md
§3.7 row 15, second overload). The selector receives the FULL snapshot — its
discriminated phase is exactly what a selector narrows on — and the hook
re-renders only when the selected value changes (guarded by isEqual,
defaulting to Object.is). A derived array/object keeps a stable reference
across isEqual-equal snapshots, so consumers get referential stability
without memo hacks (§3.9.1).
Type Parameters
Section titled “Type Parameters”T
the selected value type.
Parameters
Section titled “Parameters”selector
Section titled “selector”(snapshot) => T
maps the whole snapshot to the selected value; may be an
inline closure (identity changes are handled by useStoreSelector).
isEqual?
Section titled “isEqual?”(a, b) => boolean
optional equality for derived selections (arrays/objects);
when it reports equality the previous selection is kept by reference and no
re-render happens. Defaults to Object.is semantics.
Returns
Section titled “Returns”T
the selected value, referentially stable while equal.
Example
Section titled “Example”const phase = useWorkoutSession((s) => s.phase); // re-renders on phase change onlyconst lost = useWorkoutSession( (s) => (s.phase === 'running' || s.phase === 'resting' ? s.devices.filter((d) => d.link !== 'ready') : []), shallowEqualIds, // stable [] identity across frames);