Installation
You can install XState using your favorite package manager or embed the <script>
directly from a CDN.
Installation Snippets
using yarnbash
yarn add xstate
using yarnbash
yarn add xstate
using npmbash
npm install xstate
using npmbash
npm install xstate
using pnpmbash
pnpm install xstate
using pnpmbash
pnpm install xstate
CDN
You can embed XState from the unpkg CDN:
- XState core: https://unpkg.com/xstate@4/dist/xstate.js
- XState web: https://unpkg.com/xstate@4/dist/xstate.web.js
- Browser-friendly, ES module build
html
<script src="https://unpkg.com/xstate@4/dist/xstate.js"></script>
html
<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.
js
const { createMachine, actions, interpret } = XState; // global variable: window.XStateconst lightMachine = createMachine({// ...});const lightActor = interpret(lightMachine);
js
const { createMachine, actions, interpret } = XState; // global variable: window.XStateconst lightMachine = createMachine({// ...});const lightActor = interpret(lightMachine);