Learn all about using actors in XState.
When you run a statechart, it becomes an actor, a running process that can receive events. Often, you’ll need your actor to run other actors.
The most common type of actors you’ll invoke are promise actors. Promise actors allow you to await the result of a promise before deciding what to do next.
Sometimes it’s unclear whether you should use an action or an actor. Both appear to do similar things, executing side effects. Let’s break down the differences.
Promise actors let you model promises, but not every actor will be a promise. Callback actors give you a flexible API for managing a long-running actor.
Machine actors enable you to create machines that can act as reusable modules across your application. You can pass a machine directly to the invoke src.
Observables are streams of values emitted over time. Observables can be invoked, sending events to the parent machine.
Invoked actors can send events to their parent using the sendParent and sendBack methods. Child actors can also receive events from the parent.
You can use spawn to run actors. Actors created with spawn are spawning actors, and actors created with invoke are invoking actors.
Get working quickly with actors using our quick reference XState cheatsheet, including spawning, sending, and receiving.