XState v6 alpha
Share actors
Share one actor through Svelte context.
XState v6 is in alpha
APIs and behavior may change before the stable release.
Create the actor in a parent component and put its reference in Svelte context.
const actorRef = useActorRef(machine);
setContext(actorKey, actorRef);Descendants can read the same reference.
const actorRef = getContext(actorKey);
const count = useSelector(actorRef, (snapshot) => snapshot.context.count);This works well for a cart shared by checkout components or a session actor shared by one application shell. Create one actor per application or request.