leptos_use

Function use_timeout_fn

Source
pub fn use_timeout_fn<CbFn, Arg, D>(
    callback: CbFn,
    delay: D,
) -> UseTimeoutFnReturn<impl Fn(Arg) + Clone, Arg, impl Fn() + Clone>
where CbFn: Fn(Arg) + Clone + 'static, Arg: 'static, D: Into<MaybeSignal<f64>>,
Expand description

Wrapper for setTimeout with controls.

§Demo

Link to Demo

§Usage

let UseTimeoutFnReturn { start, stop, is_pending, .. } = use_timeout_fn(
    |i: i32| {
        // do sth
    },
    3000.0
);

start(3);

§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.