Skip to content

Function: hasContext()

Documentation / @xmachines/play-xstate / hasContext

function hasContext<TContext>(path): Guard<TContext, PlayEvent>;

Defined in: packages/play-xstate/src/guards/helpers.ts:23

Check if context has a truthy value at path

Per CONTEXT.md: Convenience helper for common guard pattern

Type Parameters

Type ParameterDefault type
TContextRecord<string, unknown>

Parameters

ParameterTypeDescription
pathstringDot-separated path to context property

Returns

Guard<TContext, PlayEvent>

Guard predicate checking if property is truthy

Example

const machine = setup({
guards: {
hasUserId: hasContext("userId"),
hasEmail: hasContext("user.email"),
},
});