Provider

Reference the provider for sharing one stepper instance.

Provider

Every definition exposes a generated provider.

Example setup

All examples on this page use this stepper definition:

import { defineStepper } from "@stepperize/react";

const checkout = defineStepper([
  { id: "shipping", title: "Shipping" },
  { id: "payment", title: "Payment" },
  { id: "review", title: "Review" },
]);
function CheckoutShell() {
  return (
    <checkout.Provider defaultStep="shipping">
      <StepperNav />
      <CheckoutPanel />
      <Actions />
    </checkout.Provider>
  );
}

Descendants call the same generated hook:

function Actions() {
  const stepper = checkout.useStepper();

  return (
    <button type="button" disabled={!stepper.canNext} onClick={() => stepper.next()}>
      Next
    </button>
  );
}

Inside the provider, checkout.useStepper() reads the shared instance. Outside it, it creates local state.

Use Provider when your layout already has the right markup and you only need a shared stepper instance in descendant components.

Props

The provider accepts the same instance options as useStepper.

PropDescription
defaultStepInitial step for uncontrolled provider state.
step / onStepChangeControlled current step. step may be a raw external string; onStepChange receives known step ids.
data / onDataChangeControlled flow data.
completed / onCompletedChangeControlled completion.
onInvalidStepCalled when a controlled step is not a known step id.
lineartrue restricts trigger and list keyboard affordances. Defaults to false.
beforeStepChangeGuard before navigation.
onStepChangeCalled after navigation succeeds.
<checkout.Provider
  step={step}
  onStepChange={setStep}
  data={values}
  onDataChange={setValues}
  linear
>
  <Checkout />
</checkout.Provider>

Use Provider for shared state with your own UI. Use Stepper.Root when the primitive UI should own the provider too.

Provider vs Stepper.Root

UseWhen
checkout.ProviderYou want shared state but custom markup.
checkout.Stepper.RootYou want shared state plus primitive list, item, trigger, content, and action components.

Both create the same kind of runtime instance. Descendants still call checkout.useStepper().

Edit on GitHub

Last updated on

On this page