Open this example in the interactive library
Live preview
Source code
// components/ReverseOrderSwitch.tsx
import { useState } from "react";
export default function ReverseOrderSwitch({
entries = ["Beta", "Alpha", "Gamma"],
}: { entries?: string[] } = {}) {
const [rev, set] = useState(false);
return (
<section>
<button aria-pressed={rev} onClick={() => set(!rev)}>
Reverse order
</button>
<ol>
{(rev ? [...entries].reverse() : entries).map((s, i) => (
<li key={i}>{s}</li>
))}
</ol>
</section>
);
}
