Struct leptos_dom::NodeRef
source · pub struct NodeRef(_);
Expand description
Contains a shared reference to a DOM node creating while using the view macro to create your UI.
#[component]
pub fn MyComponent(cx: Scope) -> Element {
let input_ref = NodeRef::new(cx);
let on_click = move |_| {
let node = input_ref
.get()
.expect("input_ref should be loaded by now")
.unchecked_into::<web_sys::HtmlInputElement>();
log!("value is {:?}", node.value())
};
view! {
cx,
<div>
// `node_ref` loads the input
<input _ref=input_ref type="text"/>
// the button consumes it
<button on:click=on_click>"Click me"</button>
</div>
}
}