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_timeout_fn

Wrapper for setTimeout with controls.

Demo

Usage

use leptos::prelude::*;
use leptos_use_timeout_fn::{use_timeout_fn, UseTimeoutFnReturn};

#[component]
fn Demo() -> impl IntoView {
let UseTimeoutFnReturn { start, stop, is_pending, .. } = use_timeout_fn(
    |i: i32| {
        // do sth
    },
    3000.0
);

start(3);

view! { }
}

Rescheduling

Calling start while a previous timer is still pending cancels that pending timer and schedules a fresh one. Only the most recent start call’s callback will fire. This matches VueUse’s useTimeoutFn semantics.

SendWrapped Return

The returned closures start and stop are sendwrapped functions. They can only be called from the same thread that called use_timeout_fn.

Server-Side Rendering

Make sure you follow the instructions in Server-Side Rendering.

On the server the callback will never be run. The returned functions are all no-ops and is_pending will always be false.

Installation

cargo add leptos-use-timeout-fn

Source

Source • Demo • Docs