useCycleList
Cycle through a list of items
Usage
Live Editor
function Demo() { const [state, next, prev] = useCycleList([ "Dog", "Cat", "Lizard", "Shark", "Whale", "Dolphin", "Octopus", "Seal", ]); return ( <div> <div>{state}</div> <div> <button onClick={() => next()}>next</button> <button onClick={() => prev()}>prev</button> </div> </div> ); };
Result
Loading...
API
useCycleList
Returns
readonly [T, (i?: number | undefined) => void, (i?: number | undefined) => void]
: A tuple with the following elements:
- The current index value of the list.
- A function to set index to prev.
- A function to set index to next.
Arguments
Argument | Description | Type | DefaultValue |
---|---|---|---|
list | cycle array | T[] (Required) | - |
i | array index | number | undefined | - |