Skip to content
This repository was archived by the owner on Jul 19, 2020. It is now read-only.

Latest commit

 

History

History
56 lines (46 loc) · 884 Bytes

lists.md

File metadata and controls

56 lines (46 loc) · 884 Bytes

Lists

Fragments

The html! macro always requires a single root node. In order to get around this restriction, it's valid to wrap content in empty tags:

{% tabs %} {% tab title="Valid" %}

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

{% endtab %}

{% tab title="Invalid" %}

/* error: only one root html element allowed */

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

{% endtab %} {% endtabs %}

Iterators

Yew supports two different syntaxes for building html from an iterator:

{% tabs %} {% tab title="Syntax Type 1" %}

html! {
    <ul class="item-list">
        { self.props.items.iter().map(renderItem).collect::<Html>() }
    </ul>
}

{% endtab %}

{% tab title="Syntax Type 2" %}

html! {
    <ul class="item-list">
        { for self.props.items.iter().map(renderItem) }
    </ul>
}

{% endtab %} {% endtabs %}