Scoped
Share stepper state with the Scoped component
Scoped is the provider for the stepper. Wrap your tree with <Scoped> so any descendant can call useStepper() from the same defineStepper and receive the same stepper instance. Without Scoped (or Stepper.Root), there is no shared stepper context.
Basic usage
import * as React from "react";
import { } from "@stepperize/react";
const { , } = (
{ : "first", : "First" },
{ : "second", : "Second" },
{ : "last", : "Last" }
);
export const = () => (
<>
< />
< />
</>
);
const = () => {
const = ();
return (
<>
{..("first", () => <>Starting with {.}</>)}
{..("second", () => <>In the middle: {.}</>)}
</>
);
};
const = () => {
const = ();
return (
< ={.. ? () => ..() : () => ..()}>
{..("last", () => "Reset", () => "Next")}
</>
);
};Props
| Name | Type | Description |
|---|---|---|
initialStep | Get.Id<Steps> | Initial active step ID |
initialMetadata | Partial<Record<Get.Id<Steps>, Metadata>> | Initial metadata per step |
children | React.ReactNode | Content to render |
import * as React from "react";
import { } from "@stepperize/react";
const { , } = (
{ : "first", : "First" },
{ : "second", : "Second" },
{ : "last", : "Last" }
);
export const = () => (
<
="second"
={{ : { : true }, : null, : null }}
>
< />
</>
);
const = () => {
const = ();
return <>Current: {....}</>;
};Nested scopes
You can nest different steppers (e.g. global wizard + local sub-steps):
import * as React from "react";
import { } from "@stepperize/react";
const = (
{ : "start", : "Start" },
{ : "middle", : "Middle" },
{ : "end", : "End" }
);
const = (
{ : "sub1", : "Sub-step 1" },
{ : "sub2", : "Sub-step 2" }
);
export const = () => (
<.>
< />
<.>
< />
</.>
</.>
);
const = () => {
const = .();
return <>Global: {....}</>;
};
const = () => {
const = .();
return <>Local: {....}</>;
};With Stepper.Root
Stepper.Root wraps content and provides the stepper via context (it uses Scoped internally). Stepper.Root accepts initialStep and initialMetadata and passes them to Scoped internally; use either Root or Scoped to set initial state.
import * as React from "react";
import { } from "@stepperize/react";
const { , } = (
{ : "first", : "First" },
{ : "second", : "Second" }
);
export const = () => (
<.>
{({ }) => (
<>
<>Current: {....}</>
< ={() => ..()}>Next</>
</>
)}
</.>
);Edit on GitHub
Last updated on