Skip to main content
Version: Next

Fragments

The html! macro accepts multiple root nodes directly. You do not need a fragment wrapper (<>...</>) at the root:

use yew::prelude::*;

html! {
<div></div>
<p></p>
};

Keyed fragments

The only legitimate use of fragment syntax is a keyed fragment.

use yew::prelude::*;

html! {
// .. siblings ..
<key="group-a">
<span>{"a1"}</span>
<span>{"a2"}</span>
</>
// .. siblings ..
};

Keyed fragments helps with reconciliation performance and node persistence in some cases.