Implement a useCycle hook that cycles through a sequence of values each time its function is called.
useCycle
export default function Component() { const [mode, cycle] = useCycle('low', 'medium', 'high'); return ( <div> <p>State: {mode}</p> <button onClick={cycle}>Cycle</button> </div> );}
The useCycle hook should accept an indefinite number of arguments, each representing a value in the sequence to cycle through.
A tuple containing the following elements:
value
cycle
Want to grow in your front end skills? Learn them the right way — build apps step-by-step while referencing best practices from Senior engineers.
Get 30% off now with BETA30 →
console.log()