Skip to content

Latest commit

 

History

History
41 lines (34 loc) · 1.14 KB

prefer-always.md

File metadata and controls

41 lines (34 loc) · 1.14 KB

Use always instead of deprecated empty string transient transitions

Suggest using the new always syntax for declaring transient (a.k.a. eventless) transitions instead of the deprecated empty string syntax.

Rule Details

XState v4.11+ provides a new always syntax for declaring transient transitions, now called eventless transitions. The empty string syntax will be deprecated in v5.

Examples of incorrect code for this rule:

// ❌ transient transition declared with an empty string
createMachine({
  states: {
    playing: {
      on: {
        '': [
          { target: 'win', cond: 'didPlayerWin' },
          { target: 'lose', cond: 'didPlayerLose' },
        ],
      },
    },
  },
})

Examples of correct code for this rule:

// ✅ using the new "always" syntax
createMachine({
  states: {
    playing: {
      always: [
        { target: 'win', cond: 'didPlayerWin' },
        { target: 'lose', cond: 'didPlayerLose' },
      ],
    },
  },
})