2023-07-16 01:07:52 +01:00
|
|
|
use leptos::*;
|
|
|
|
use leptos_use::docs::demo_or_body;
|
|
|
|
use leptos_use::{use_raf_fn, utils::Pausable};
|
|
|
|
|
|
|
|
#[component]
|
2023-07-27 18:06:36 +01:00
|
|
|
fn Demo() -> impl IntoView {
|
|
|
|
let (count, set_count) = create_signal(0);
|
2023-07-16 01:07:52 +01:00
|
|
|
|
|
|
|
let Pausable {
|
|
|
|
pause,
|
|
|
|
resume,
|
|
|
|
is_active,
|
2023-07-27 18:06:36 +01:00
|
|
|
} = use_raf_fn(move |_| {
|
2023-07-16 01:07:52 +01:00
|
|
|
set_count.update(|count| *count += 1);
|
|
|
|
});
|
|
|
|
|
2023-07-27 19:48:21 +01:00
|
|
|
view! {
|
2023-10-23 20:15:05 -05:00
|
|
|
<div>Count: {count}</div>
|
2023-07-27 19:48:21 +01:00
|
|
|
<button on:click=move |_| pause() disabled=move || !is_active()>
|
|
|
|
Pause
|
|
|
|
</button>
|
|
|
|
<button on:click=move |_| resume() disabled=is_active>
|
|
|
|
Resume
|
|
|
|
</button>
|
2023-07-16 01:07:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
_ = console_log::init_with_level(log::Level::Debug);
|
|
|
|
console_error_panic_hook::set_once();
|
|
|
|
|
2023-07-27 18:06:36 +01:00
|
|
|
mount_to(demo_or_body(), || {
|
2023-07-27 19:48:21 +01:00
|
|
|
view! { <Demo/> }
|
2023-07-16 01:07:52 +01:00
|
|
|
})
|
|
|
|
}
|