On Remove Element

The on_remove_elem special attribute allows you to register a function that will be called when the element is removed from the DOM.


#![allow(unused)]
fn main() {
let mut div: VirtualNode = html! {
    <div></div>
};

let special_attributes = &mut div.as_elem_mut().unwrap().special_attributes;
special_attributes.set_key("some-key");
special_attributes
    .set_on_remove_element(move |_elem: web_sys::Element| {
        // ...
    })
    .unwrap();
}

Macro shorthand

You can also use the html! macro to set the on_remove_element function.


#![allow(unused)]
fn main() {
let _ = html! {
  <div
    key="some-key"
	on_remove_element = move |_element: web_sys::Element| {
	  // ...
	}
  >
    Before
  </div>
}
}