Skip to content

How to dynamically generate elements list and pass it as typed children property? #2529

Answered by WorldSEnder
art-in asked this question in Q&A
Discussion options

You must be logged in to vote

The html_nested! macro will come in handy and was made for this use case.

html ! {
    <List>
-       {for (0..3).map(|n: i32| html ! {
+       {for (0..3).map(|n: i32| html_nested ! {
            <ListItem value={n.to_string()} />
        })}
    </List>
}

The more technical reason this is necessary is that the html! macro erases the type of the component and always results in an expression of type Html (an alias for VNode you see in the error), while html_nested! preserves the top-most component type.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by art-in
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants