Function use_raf_fn

Source
pub fn use_raf_fn(
    callback: impl Fn(UseRafFnCallbackArgs) + 'static,
) -> Pausable<impl Fn() + Clone + Send + Sync, impl Fn() + Clone + Send + Sync>
Expand description

Call function on every requestAnimationFrame. With controls of pausing and resuming.

§Demo

Link to Demo

§Usage

use leptos_use::utils::Pausable;
let (count, set_count) = signal(0);

let Pausable { pause, resume, is_active } = use_raf_fn(move |_| {
    set_count.update(|count| *count += 1);
});

view! { <div>Count: { count }</div> }
}

You can use use_raf_fn_with_options and set immediate to false. In that case you have to call resume() before the callback is executed.

§SendWrapped Return

The returned closures pause and resume are sendwrapped functions. They can only be called from the same thread that called use_interval_fn.

§Server-Side Rendering

On the server this does basically nothing. The provided closure will never be called.