1import { defineStepper } from "@stepperize/react";
2import { useState } from "react";
3
4const checkout = defineStepper([
5 { id: "account", title: "Account" },
6 { id: "shipping", title: "Shipping" },
7 { id: "review", title: "Review" },
8 { id: "done", title: "Done" },
9]);
10
11export function Checkout() {
12 const [email, setEmail] = useState("");
13 const stepper = checkout.useStepper({
14 async guard({ from, direction }) {
15 if (direction !== "next") return true;
16 if (from.id === "account") return isEmail(email);
17 if (from.id === "review") await placeOrder();
18 },
19 });
20
21 return stepper.match({
22 account: () => <Account onEmail={setEmail} />,
23 shipping: () => <Shipping />,
24 review: () => <Review />,
25 done: () => <Done />,
26 });
27}