Provider and Hooks API
This page documents the React binding surface in detail.
JourneyProvider
<JourneyProvider
journey={journey}
persistence={{ key: "signup", version: 1 }}
history={{ maxHistory: 20 }}
resetOnJourneyChange={false}
>
<JourneyStepRenderer />
</JourneyProvider>
Props
journey(required):JourneyReactDefinitionmachine(optional): external machine instancepersistence(optional): forwarded to internal machine creationhistory(optional): forwarded to internal machine creationresetOnJourneyChange(optional, defaultfalse)children(required)
If machine is provided, provider uses that machine and does not create internal one.
JourneyStepRenderer
<JourneyStepRenderer fallback={<NotFoundStep />} />
- Renders
journey.steps[snapshot.current].component - Uses
fallbackwhen current step has no mapped component
useJourneySnapshot
const snapshot = useJourneySnapshot<Context, StepId>();
- Subscribes via
useSyncExternalStore - Triggers rerender when machine snapshot changes
useJourneyApi
const api = useJourneyApi<Context, StepId, CustomEvent, PayloadMap>();
await api.next();
await api.back();
await api.submit();
await api.close();
await api.goTo("review");
await api.send({ type: "retry" });
api.updateContext((ctx) => ({ ...ctx, dirty: true }));
api.clearStepError();
api.reset();
api.trimHistory(10);
api.clearHistory();
useJourney
const { snapshot, api } = useJourney<Context, StepId, CustomEvent, PayloadMap>();
Returns the combined snapshot + API object.
Provider Boundary Error
Hooks throw if used outside provider:
useJourney must be used within <JourneyProvider>.
This is intentional to fail fast and avoid silent null behavior.