Function: hasContext()
API / @xmachines/play-xstate / hasContext
function hasContext<TContext>(path): Guard<TContext, PlayEvent>;Defined in: packages/play-xstate/src/guards/helpers.ts:24
Tells you if the context holds a value at the path, and that the value is truthy
Type Parameters
| Type Parameter | Default type |
|---|---|
TContext | Record<string, unknown> |
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | The path to the context property, with a dot between two segments |
Returns
The guard predicate. It tests the property for a truthy value
Example
const machine = setup({ guards: { hasUserId: hasContext("userId"), hasEmail: hasContext("user.email"), },});Deprecated
This function is part of the guard utilities, and the next major version removes them. Write a plain typed predicate instead.