Leptos-Use Guide

use_raf_fn

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

Demo

Usage

use leptos::*;
use leptos_use::use_raf_fn;
use leptos_use::utils::Pausable;

#[component]
fn Demo() -> impl IntoView {
let (count, set_count) = create_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.

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

Types

Source

SourceDemoDocs