# Introduction

> Typed multi-step flows for React, from one definition.

Framework: React (`@stepperize/react`), Stepperize v9.
Source: https://stepperize.com/docs/v9/react

Stepperize is for flows where someone moves through named steps: checkout,
onboarding, surveys, import wizards, approval flows and multi-step forms.

You describe the steps once. The definition gives you a typed hook, a provider
and a set of accessible, unstyled components that all share the same step ids.

```tsx
import { defineStepper } from "@stepperize/react";
import { z } from "zod";

const checkout = defineStepper([
  { id: "shipping", title: "Shipping", schema: z.object({ address: z.string().min(1) }) },
  { id: "payment", title: "Payment", schema: z.object({ card: z.string().length(16) }) },
  { id: "review", title: "Review" },
]);

function Checkout() {
  const stepper = checkout.useStepper({ onFinish: (output) => placeOrder(output) });

  return (
    <section>
      <h2>{stepper.current.title}</h2>

      {stepper.match({
        shipping: (_step, data) => <ShippingForm defaultValues={data} />,
        payment: (_step, data) => <PaymentForm defaultValues={data} />,
        review: () => <Review data={stepper.data} />,
      })}

      <button type="button" disabled={stepper.isFirst} onClick={() => stepper.prev()}>
        Back
      </button>
      <button type="button" onClick={() => stepper.next(readForm())}>
        {stepper.isLast ? "Place order" : "Continue"}
      </button>
    </section>
  );
}
```

A flow built with the primitives, running:

The live demo runs in the browser. Its source ([react/ReactDemo.tsx](https://github.com/damianricobelli/stepperize/blob/main/apps/docs/src/components/framework-demos/react/ReactDemo.tsx)):

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

// Module scope: one definition, shared by every instance of this component.
const { Stepper } = defineStepper([
	{ id: "account", title: "Account", description: "Who you are" },
	{ id: "plan", title: "Plan", description: "What you need" },
	{ id: "done", title: "Done", description: "All set" },
]);

export default function ReactDemo() {
	return (
		<Stepper.Root
			className="not-prose my-4 flex flex-col gap-4 rounded-lg border p-4 text-sm"
			data-demo="react"
		>
			{/* The render prop receives the stepper: `isFinished` and `isLast` come from the flow, not local state. */}
			{(stepper) => (
				<>
					<Stepper.List className="flex gap-2">
						{(step, index) => (
							<Stepper.Item key={step.id} step={step.id} className="flex-1">
								<Stepper.Trigger className="flex w-full items-center gap-2 rounded-md border px-3 py-2 text-left data-[state=current]:border-fd-primary data-[state=current]:bg-fd-accent">
									<Stepper.Indicator className="flex size-6 shrink-0 items-center justify-center rounded-full border text-xs data-[state=complete]:bg-fd-primary data-[state=complete]:text-fd-primary-foreground">
										{index + 1}
									</Stepper.Indicator>
									<span className="flex flex-col">
										<Stepper.Title className="font-medium" />
										<Stepper.Description className="text-xs text-fd-muted-foreground" />
									</span>
								</Stepper.Trigger>
							</Stepper.Item>
						)}
					</Stepper.List>

					<Stepper.Content
						step="account"
						className="rounded-md bg-fd-muted p-3"
					>
						Create your account.
					</Stepper.Content>
					<Stepper.Content step="plan" className="rounded-md bg-fd-muted p-3">
						Pick the plan that fits.
					</Stepper.Content>
					<Stepper.Content step="done" className="rounded-md bg-fd-muted p-3">
						{stepper.isFinished
							? "Finished. Thanks!"
							: "Press Finish to complete the flow."}
					</Stepper.Content>

					<div className="flex items-center gap-2">
						<Stepper.Prev className="rounded-md border px-3 py-1 disabled:opacity-40">
							Back
						</Stepper.Prev>
						<Stepper.Next className="rounded-md border px-3 py-1 aria-disabled:opacity-40">
							{stepper.isLast ? "Finish" : "Continue"}
						</Stepper.Next>
						<span
							data-step
							className="ml-auto text-xs text-fd-muted-foreground"
						>
							Step {stepper.index + 1} of {stepper.steps.length}
						</span>
					</div>
				</>
			)}
		</Stepper.Root>
	);
}
```

## Is it a form library?

No. Stepperize owns the **flow**: which step is current, moving between steps,
what each step saved and which steps are complete. Your form library, or a few
lines of your own, owns the fields. See
[Building multi-step forms](https://stepperize.com/docs/v9/react/forms).

## What you get

- **One call moves forward.** `next(data)` saves the step's data, validates it
  against the step's schema and moves on. It resolves with what happened
  instead of throwing.
- **Typed everywhere.** Step ids, each step's data and your own fields
  (`title`, `icon`, anything) are inferred from the definition.
- **Branching as data.** A `next` map decides where each step leads from its
  validated data, and a flow can have more than one ending.
- **Resumable.** One `snapshot` goes in, one `onChange` comes out. The current
  step can follow the URL with a single option.
- **Accessible primitives.** Roles, keyboard navigation, focus and
  announcements are handled for you.
- **Small.** About 2.7 KiB for the hooks and 5.4 KiB with the primitives, min +
  gzip, with no third-party dependencies.

## Next

- [Installation](https://stepperize.com/docs/v9/react/installation): Add the package to a React 18 or 19 project.

- [Your first stepper](https://stepperize.com/docs/v9/react/first-stepper): A working flow, built in four small steps.

- [Core concepts](https://stepperize.com/docs/v9/react/concepts/steps): Steps, the flow, the lifecycle of a move and step state.

- [Multi-step forms](https://stepperize.com/docs/v9/react/forms): Patterns and complete examples for each form library.

- [Coming from v8](https://stepperize.com/docs/v9/react/migration): What changed, and a codemod that does most of it.

- [Without React](https://stepperize.com/docs/v9/core): The same state machine in tests, servers and agents.
