Not only React anymoreStepperize now runs in Vue, Svelte, Solid, Angular, Lit, and HTML
Skip to Content
Stepperize

defineStepper

The definition and everything it returns.

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

const checkout = defineStepper(steps, options?);
ArgumentDescription
stepsAn array of steps. Each needs a unique id; schema types and validates its data; every other field is yours.
optionsDefaults for every flow created from this definition. See Options.

It returns:

stepsThe array you passed.
useStepper(options?)A flow owned by the calling component.
useStepperContext(selector?)The flow of the nearest Provider or Stepper.Root.
ProviderShares one flow with the components below.
StepperThe primitives. Not in /headless.
create(options?)A flow without Solid. See Core.

useStepper

const stepper = checkout.useStepper();
const stepper = checkout.useStepper({ linear: true, onFinish });
const stepper = checkout.useStepper(() => ({ step: params.step }));

It returns the stepper as a reactive object: reads are tracked, so JSX, memos and effects follow the flow. Do not destructure its state.

  • Options can be an object or a function. Pass a function when an option depends on a signal or on props.
  • Callbacks (onChange, onFinish, onInvalidStep, guard) and next are read when the flow calls them, so it always calls the latest, even one changed in the same batch as the action, or under a Suspense that is still loading.
  • linear and step are followed when they change, once the component is mounted.
  • snapshot is read once, when the flow is created.
  • An option that is undefined keeps the definition's default, like an absent prop.
  • The flow is destroyed with its owner: the component, or the createRoot it was called under.
  • On the server it renders the current step and runs no callback.

useStepperContext

const stepper = checkout.useStepperContext();
const index = checkout.useStepperContext((stepper) => stepper.index); // Accessor<number>

Without arguments it returns the shared reactive stepper. With a selector it returns a memo of its result; the selector receives an immutable view of the flow. Outside the flow's Provider or Stepper.Root it throws SZ100.

Provider

<checkout.Provider linear snapshot={saved} onChange={save} onFinish={submit}>
  {props.children}
</checkout.Provider>

Every option is a prop, read like useStepper's options. It renders its children and no element. Providers nest: each component reads the nearest one of its own definition.

Types

Everything @stepperize/core exports as a type is re-exported: Stepper<S>, Options<S>, Snapshot<S>, Result<S>, Id<S> and the rest.

The props of the primitives are exported too: RootProps<S>, ListProps<S, T>, ItemProps<S, T>, ContentProps<S, T>, ButtonProps<T> and TextProps<T>, where T is what as renders (its default tag when omitted). PolymorphicProps<T, Own> builds the same shape for your own wrappers.

Edit on GitHub

Last updated on

On this page