Skip to content

Function: contextFieldMatches()

API / @xmachines/play-xstate / contextFieldMatches

function contextFieldMatches<TContext>(fieldPath, expectedValue): Guard<TContext, PlayEvent>;

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

Check if a context field matches an expected value.

  • Accepts an explicit dot-separated field path (e.g. "user.role")
  • Uses strict equality for primitives, deep structural equality for objects
  • Object comparison is key-order-insensitive: {a:1,b:2} equals {b:2,a:1}
  • Supports Date, RegExp, class instances, nested objects and arrays via dequal/lite
  • Does NOT use substring matching — "a" will not match "active"

For XState state-node matching, use the built-in in: guard syntax instead.

Type Parameters

Type ParameterDefault type
TContextRecord<string, unknown>

Parameters

ParameterTypeDescription
fieldPathstringDot-separated path to context property (e.g., “status”, “user.role”)
expectedValueunknownValue to compare against (string, object, Date, etc.)

Returns

Guard<TContext, PlayEvent>

Guard predicate checking if context field matches