use_raf_fn
Call function on every requestAnimationFrame. With controls of pausing and resuming.
Demo
Usage
use leptos::prelude::*;
use leptos_use::use_raf_fn;
use leptos_use::utils::Pausable;
#[component]
fn Demo() -> impl IntoView {
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.
Feature
This function is only available if the crate feature
use_raf_fn
is enabled