XState v6 alpha
Server rendering
Use XState actors with server-rendered React.
XState v6 is in alpha
APIs and behavior may change before the stable release.
Create actors per request. Do not share a running actor between users.
Get a persisted snapshot on the server, serialize it with the page and restore it on the client.
const [snapshot] = useActor(machine, {
snapshot: window.__ACTOR_SNAPSHOT__
});Keep browser-only effects out of server transitions. Start them after hydration or in actor logic that only runs in the browser.
For example, restore an order actor from the database for one request, or send a persisted checkout snapshot with the page so the browser resumes the same step.