--- title: Quick start description: Create and run your first XState state machine. --- XState helps you model how software responds to events. This example models a media player with three states. ## Install XState ```bash npm install xstate@beta ``` ## Create a state machine ```ts stately="Media player" import { createMachine } from 'xstate'; const playerMachine = createMachine({ initial: 'stopped', states: { stopped: { on: { play: { target: 'playing' } } }, playing: { on: { pause: { target: 'paused' }, stop: { target: 'stopped' } } }, paused: { on: { play: { target: 'playing' }, stop: { target: 'stopped' } } } } }); ``` Start the actor and send it two events. ```ts import { createActor } from 'xstate'; const player = createActor(playerMachine).start(); player.send({ type: 'pause' }); console.log(player.getSnapshot().value); // 'stopped' player.send({ type: 'play' }); console.log(player.getSnapshot().value); // 'playing' ``` The first `pause` event does not change the state. The `stopped` state does not define what should happen for that event. The player can only follow the transitions you define. Starting from `stopped`, send `play`, then `pause`. Sending another `pause` leaves the player in `paused`. Send `stop` to return to `stopped`. The machine describes the behavior. `createActor(...)` creates an instance and `start()` starts it. You can send events to the actor and read its current snapshot. ## Next steps - [Learn why state machines are useful](why-state-machines.md). - [Build your first machine step by step](your-first-machine.md). - [Choose between XState and XState Store](choose-xstate.md).