Function wasm_react::hooks::use_js_ref
source · [−]pub fn use_js_ref<T: JsCast>(init: Option<T>) -> JsRefContainer<T>
Expand description
This hook can persist JS data through the entire lifetime of the component.
Use this if you need JS to set the ref value. If you only need to mutate the
data from Rust, use use_ref()
instead.
Example
impl Component for MyComponent {
fn render(&self) -> VNode {
let input_element = use_js_ref(None);
h!(div)
.build(c![
h!(input)
.ref_container(&input_element)
.html_type("text")
.build(c![])
])
}
}