Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

use_cycle_list

Cycle through a list of items.

Demo

Usage

use leptos::prelude::*;
use leptos::logging::log;
use leptos_use_cycle_list::{use_cycle_list, UseCycleListReturn};

#[component]
fn Demo() -> impl IntoView {
let UseCycleListReturn { state, next, prev, .. } = use_cycle_list(
    vec!["Dog", "Cat", "Lizard", "Shark", "Whale", "Dolphin", "Octopus", "Seal"]
);

log!("{}", state.get()); // "Dog"

prev();

log!("{}", state.get()); // "Seal"

view! { }
}

Installation

cargo add leptos-use-cycle-list

Options

UseCycleListOptions

Options for use_cycle_list_with_options.

Every option is set with a builder method of the same name, e.g. UseCycleListOptions::default().initial_value(...). See also the API docs.

initial_value

Type: Option<MaybeRwSignal<T>>

The initial value of the state. Can be a Signal. If none is provided the first entry of the list will be used.

fallback_index

Type: usize

The default index when the current value is not found in the list. For example when get_index_of returns None.

get_position

Type: fn(&T, &Vec<T>) -> Option<usize>

Custom function to get the index of the current value. Defaults to Iterator::position()

Source

Source • Demo • Docs