Function: negateGuard()
Documentation / @xmachines/play-xstate / negateGuard
function negateGuard<TContext, TEvent>(guard): ComposedGuard;Defined in: packages/play-xstate/src/guards/compose.ts:203
Negate a guard using XState’s not() helper
Inverts a guard’s result—if the guard passes, NOT fails; if guard fails, NOT passes.
Uses XState’s built-in not() helper for proper serialization.
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
TContext | any | State machine context type |
TEvent | any | Event type |
Parameters
| Parameter | Type | Description |
|---|---|---|
guard | string | Guard<TContext, TEvent> | Guard predicate or guard name to negate |
Returns
XState not() guard negation
Example
NOT composition with named guard
import { setup } from "xstate";import { negateGuard } from "@xmachines/play-xstate";
const machine = setup({ guards: { isGuest: ({ context }) => !context.userId, },}).createMachine({ on: { accessDashboard: { // Allow if NOT a guest (i.e., authenticated) guard: negateGuard("isGuest"), target: "dashboard", }, },});See
- composeGuards for AND composition
- composeGuardsOr for OR composition