pub fn use_click_away<'hook, F>(
node: NodeRef,
callback: F,
) -> impl 'hook + Hook<Output = ()>Expand description
A hook that triggers a callback when user clicks outside the target element.
§Example
use yew_hooks::prelude::*;
#[function_component(UseClickAway)]
fn click_away() -> Html {
let node = use_node_ref();
use_click_away(node.clone(), move |_: Event| {
debug!("Clicked outside!");
});
html! {
<div ref={node}>
{ "Try to click outside of this area." }
</div>
}
}§Note
When used in function components and hooks, this hook is equivalent to:
pub fn use_click_away<F>(node: NodeRef, callback: F)
where
F: Fn(Event) + 'static,
{
/* implementation omitted */
}