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:
- 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
<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);