Course lesson

Replace Inline Functions with String Shorthands

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.

Duration
2 min
Access
Pro
Transcript
Available

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.

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