Open this example in the interactive library
Live preview
Source code
// components/CyclingOptionButton.tsx
import { useState } from "react";
export default function CyclingOptionButton({
options = ["Clay", "Slate", "Ink"],
}: { options?: string[] } = {}) {
const [index, set] = useState(0);
return (
<button
disabled={!options.length}
onClick={() => set((i) => (i + 1) % options.length)}
>
Finish: {options[index % options.length] ?? "Unavailable"}
</button>
);
}
