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_raf_fn

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

Demo

Usage

use leptos::prelude::*;
use leptos_use_raf_fn::use_raf_fn;
use leptos_use_filters::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

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

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

Installation

cargo add leptos-use-raf-fn

Options

UseRafFnOptions

Options for use_raf_fn_with_options.

Every option is set with a builder method of the same name, e.g. UseRafFnOptions::default().immediate(...). See also the API docs.

immediate

Type: bool

Start the requestAnimationFrame loop immediately on creation. Defaults to true. If false, the loop will only start when you call resume().

Types

Source

Source • Demo • Docs