Skip to content
Version: XState v4

Installation

You can install XState using your favorite package manager or embed the <script> directly from a CDN.

Installation Snippets​

using yarn
yarn add xstate
using npm
npm install xstate

CDN​

You can embed XState from the unpkg CDN:

<script src="https://unpkg.com/xstate@4/dist/xstate.js"></script>

The variable XState will be available globally, which will give you access to the top-level exports.

const { createMachine, actions, interpret } = XState; // global variable: window.XState

const lightMachine = createMachine({
// ...
});

const lightActor = interpret(lightMachine);