Skip to content

useWorkoutSession

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.

WorkoutSessionSnapshot

the current WorkoutSessionSnapshot.

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.
}

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).

T

the selected value type.

(snapshot) => T

maps the whole snapshot to the selected value; may be an inline closure (identity changes are handled by useStoreSelector).

(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.

T

the selected value, referentially stable while equal.

const phase = useWorkoutSession((s) => s.phase); // re-renders on phase change only
const lost = useWorkoutSession(
(s) => (s.phase === 'running' || s.phase === 'resting'
? s.devices.filter((d) => d.link !== 'ready')
: []),
shallowEqualIds, // stable [] identity across frames
);