mirror of
https://github.com/adoyle0/leptos-use.git
synced 2025-02-02 19:04:15 -05:00
bd5d4ee3ff
use_scroll demo finished, docs cosmetics
34 lines
965 B
Rust
34 lines
965 B
Rust
use leptos::*;
|
|
use leptos_use::docs::demo_or_body;
|
|
use leptos_use::use_throttle_fn;
|
|
|
|
#[component]
|
|
fn Demo(cx: Scope) -> impl IntoView {
|
|
let (click_count, set_click_count) = create_signal(cx, 0);
|
|
let (throttled_count, set_throttled_count) = create_signal(cx, 0);
|
|
|
|
let throttled_fn = use_throttle_fn(move || set_throttled_count(throttled_count() + 1), 1000.0);
|
|
|
|
view! { cx,
|
|
<button
|
|
on:click=move |_| {
|
|
set_click_count(click_count() + 1);
|
|
throttled_fn();
|
|
}
|
|
>
|
|
"Smash me!"
|
|
</button>
|
|
<div class="note">"Delay is set to 1000ms for this demo."</div>
|
|
<p>"Button clicked: " { click_count }</p>
|
|
<p>"Event handler called: " { throttled_count }</p>
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
_ = console_log::init_with_level(log::Level::Debug);
|
|
console_error_panic_hook::set_once();
|
|
|
|
mount_to(demo_or_body(), |cx| {
|
|
view! { cx, <Demo /> }
|
|
})
|
|
}
|