pub fn use_event_with_window<'hook, T, F, E>(
event_type: T,
callback: F,
) -> impl 'hook + Hook<Output = ()>
Expand description
A hook that subscribes a callback to events only for window.
If you want to specify an event target, use use_event
.
§Example
use yew_hooks::prelude::*;
#[function_component(UseEvent)]
fn event() -> Html {
use_event_with_window("keypress", move |e: KeyboardEvent| {
debug!("{} is pressed!", e.key());
});
html! {
<>
{ "Press any key on your awesome keyboard!" }
</>
}
}
§Note
When used in function components and hooks, this hook is equivalent to:
pub fn use_event_with_window<T, F, E>(event_type: T, callback: F)
where
T: Into<Cow<'static, str>>,
F: Fn(E) + 'static,
E: From<JsValue>,
{
/* implementation omitted */
}