mirror of
https://github.com/adoyle0/leptos-use.git
synced 2025-01-23 09:09:21 -05:00
35 lines
789 B
Rust
35 lines
789 B
Rust
use leptos::*;
|
|
use leptos_use::docs::demo_or_body;
|
|
use leptos_use::{use_raf_fn, 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>
|
|
<button on:click=move |_| pause() disabled=move || !is_active()>
|
|
Pause
|
|
</button>
|
|
<button on:click=move |_| resume() disabled=is_active>
|
|
Resume
|
|
</button>
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
_ = console_log::init_with_level(log::Level::Debug);
|
|
console_error_panic_hook::set_once();
|
|
|
|
mount_to(demo_or_body(), || {
|
|
view! { <Demo/> }
|
|
})
|
|
}
|