Function use_ref

Source
pub fn use_ref<T>() -> Arc<T>
where T: Default + Send + Sync + 'static,
Expand description

use_ref can be used to obtain a persistent reference to an object. The object returned from ref is guaranteed to be the same object on every subsequent call to a component’s render-function. The most common use case is with HtmlNodes:

let my_div = use_ref::<DomRef>()

rsx!(
    <div ref=my_div />
)

where my_div will contain a reference to the div element after it has been rendered.

This can be used in an effect to manipulate the DOM directly:

use_effect((), |_| {
    my_div.get().set_inner_text("Hello, world!");
})