leptos-use/examples/use_window_focus/src/main.rs
2023-07-27 19:48:21 +01:00

35 lines
793 B
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use leptos::*;
use leptos_use::docs::demo_or_body;
use leptos_use::use_window_focus;
#[component]
fn Demo() -> impl IntoView {
let start_message = "💡 Click somewhere outside of the document to unfocus.";
let (message, set_message) = create_signal(start_message);
let focused = use_window_focus();
let _ = watch(
focused,
move |focused, _, _| {
if *focused {
set_message(start_message);
} else {
set_message(" Tab is unfocused")
}
},
false,
);
view! { <div>{message}</div> }
}
fn main() {
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
mount_to(demo_or_body(), || {
view! { <Demo/> }
})
}