import { useState } from "react"; type CycleState = [T, (index?: number) => void]; export const useCycle =

(...args: P[]): CycleState

=> { const [cycleIndex, setCycleIndex] = useState(0); const cycle = (index?: number) => { setCycleIndex((i) => index ?? (i === args.length - 1 ? 0 : i + 1)); }; return [args[cycleIndex], cycle]; };