R
fn

useCycleList

v0.0.15testeddemo

Cycle through a list of items, with `next`/`prev`/`shift`/`go` controls. Supports a reactive list — the index is kept valid when the list changes.

Examples

ts
const { state, next, prev } = useCycleList(['a', 'b', 'c']);
next(); // state.value === 'b'
ts
const { index } = useCycleList(['a', 'b', 'c']);
index.value = 2; // jump directly to 'c'

Demo

Loading demo…

Signature

ts
export function useCycleList<T>(
  list: MaybeRefOrGetter<T[]>,
  options: UseCycleListOptions<T> ={ ... }

Type Parameters

T

Parameters

ParameterTypeDescription
listMaybeRefOrGetter<T[]>The list to cycle through (can be reactive)
options?UseCycleListOptions<T>Options

Returns

UseCycleListReturn<T>State and controls