# defineStepper

> The definition and everything it returns.

Framework: Solid (`@stepperize/solid`), Stepperize v9.
Source: https://stepperize.com/docs/v9/solid/api/define-stepper

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

const checkout = defineStepper(steps, options?);
```

| Argument | Description |
| --- | --- |
| `steps` | An array of steps. Each needs a unique `id`; `schema` types and validates its data; every other field is yours. |
| `options` | Defaults for every flow created from this definition. See [Options](https://stepperize.com/docs/v9/solid/api/options). |

It returns:

| | |
| --- | --- |
| `steps` | The array you passed. |
| `useStepper(options?)` | A flow owned by the calling component. |
| `useStepperContext(selector?)` | The flow of the nearest `Provider` or `Stepper.Root`. |
| `Provider` | Shares one flow with the components below. |
| `Stepper` | The [primitives](https://stepperize.com/docs/v9/solid/api/primitives). Not in `/headless`. |
| `create(options?)` | A flow without Solid. See [Core](https://stepperize.com/docs/v9/core). |

## useStepper

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

It returns the [stepper](https://stepperize.com/docs/v9/solid/api/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

```ts
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](https://stepperize.com/docs/v9/core/errors#sz100).

## Provider

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

Every [option](https://stepperize.com/docs/v9/solid/api/options) 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.
