mirror of
https://github.com/adoyle0/leptos-use.git
synced 2025-03-13 17:09:50 -04:00
37 lines
854 B
Rust
37 lines
854 B
Rust
use leptos::*;
|
|
use leptos_use::docs::demo_or_body;
|
|
use leptos_use::{use_timeout_fn, UseTimeoutFnReturn};
|
|
|
|
#[component]
|
|
fn Demo() -> impl IntoView {
|
|
const DEFAULT_TEXT: &str = "Please wait for 3 seconds";
|
|
|
|
let (text, set_text) = create_signal(DEFAULT_TEXT.to_string());
|
|
let UseTimeoutFnReturn {
|
|
start, is_pending, ..
|
|
} = use_timeout_fn(
|
|
move |_| {
|
|
set_text("Fired!".to_string());
|
|
},
|
|
3000.0,
|
|
);
|
|
|
|
let restart = move |_| {
|
|
set_text(DEFAULT_TEXT.to_string());
|
|
start(());
|
|
};
|
|
|
|
view! {
|
|
<p>{text}</p>
|
|
<button on:click=restart disabled=is_pending>"Restart"</button>
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
_ = console_log::init_with_level(log::Level::Debug);
|
|
console_error_panic_hook::set_once();
|
|
|
|
mount_to(demo_or_body(), || {
|
|
view! { <Demo/> }
|
|
})
|
|
}
|