Fragments

The html! macro always requires a single root node. In order to get around this restriction, you can use an “empty tag” (these are also called “fragments”).

  • Valid
  • Invalid
  1. use yew::prelude::*;
  2. html! {
  3. <>
  4. <div></div>
  5. <p></p>
  6. </>
  7. };
  1. use yew::prelude::*;
  2. // error: only one root html element allowed
  3. html! {
  4. <div></div>
  5. <p></p>
  6. };