API Reference
Context

Context

The steps context lets any component deep in the tree access and control the wizard state without prop drilling.


useStepsContext

Reads the current steps context. Must be called inside a <Steps> provider or a <StepsProvider>.

import { useStepsContext } from 'react-formsteps-core';
 
const {
  currentStep,
  totalSteps,
  isFirst,
  isLast,
  next,
  prev,
  goTo,
  formData,
  setStepData,
  schemas,
} = useStepsContext();

Context value

KeyTypeDescription
currentStepnumberCurrent step index (0-based)
totalStepsnumberTotal number of steps
isFirstbooleantrue when on step 0
isLastbooleantrue when on the last step
next() => voidAdvance to the next step
prev() => voidGo back to the previous step
goTo(index: number) => voidJump to any step by index
formDataRecord<string, unknown>Accumulated data from all steps
setStepData(step: number, data: Record<string, unknown>) => voidMerge data for a step into the accumulated store
schemasZodType[]Zod schemas for each step

Notes

  • Throws Error: useStepsContext must be used within a StepsProvider if called outside a provider.

StepsProvider

Headless context provider for use without the UI components package. Gives full access to the context without rendering any UI.

import { StepsProvider, useStepsContext } from 'react-formsteps-core';
 
function App() {
  return (
    <StepsProvider schemas={[schema1, schema2]} onSubmit={(data) => console.log(data)}>
      <MyCustomWizard />
    </StepsProvider>
  );
}
 
function MyCustomWizard() {
  const { currentStep, next, prev, isLast } = useStepsContext();
  // full control, bring your own UI
  return <div>...</div>;
}

Props

PropTypeDefaultDescription
schemasZodType[]Required. One schema per step. Determines totalSteps
onSubmit(data: Record<string, unknown>) => voidCalled after final validation succeeds
initialStepnumber0Starting step index
childrenReact.ReactNodeTree that can consume useStepsContext

When to use StepsProvider vs <Steps>

StepsProvider (core)<Steps> (ui)
Renders UINo — headlessYes — wraps children in a div
Requires react-formsteps-uiNoYes
Use caseCustom UI, existing design systemsQuick start with pre-built components