1×
Become a member
to unlock all features

Create egghead account to access 5000+ tutorials and resources from expert developers.

Create account
Autoplay

    Replace Inline Functions with String Shorthands

    xstateXState
    >=4.6.7

    It is considered best practice to use the string shorthand for actions, guards, and more when configuring an XState Machine. We do this by providing a second argument to the Machine factory function: the options object.

    On this object, we can define our actions, guards, activities, services and more. We then refer to the name of these functions with a string of the same name.

    javascript//...
    broken: {
      entry: ['logBroken']
    }
    //...
    // In the options object
    {
      actions: {
        logBroken: (context, event) => { console.log('yo I am broke') }
      }
    }