Skip to content

Latest commit

 

History

History
20 lines (17 loc) · 573 Bytes

guards.md

File metadata and controls

20 lines (17 loc) · 573 Bytes

Guards

Transitions can also be guarded. This allows you to add a condition that needs to pass, in order for the transition to successfully fire. Guards are basically functions that should return a boolean. They have access to the interal context of the machine. When the guard evaluates as true, the transition is allowed.

const config = {
  init: 'start',
  states: {
    start: {
      CHANGE: {
        target: 'end',
        guard: (s: MachineState<{ ... }>) => s.context?.allowed,
      },
    },
    end: {},
  },
};