Open this example in the interactive library
Live preview
Source code
// components/RoundRobinTeams.tsx
import { useState } from "react";
export default function RoundRobinTeams({
entries = ["Beta", "Alpha", "Gamma"],
}: { entries?: string[] } = {}) {
const [teams, set] = useState(2);
return (
<section>
<label>
Teams
<input
type="range"
min={1}
max={5}
value={teams}
onChange={(e) => set(+e.target.value)}
/>
</label>
{Array.from({ length: teams }, (_, i) => (
<p key={i}>
Team {i + 1}: {entries.filter((_, j) => j % teams === i).join(", ")}
</p>
))}
</section>
);
}
