DioxusLabs / DioxusLabs/dioxus
Iterable Children
- Dominant language
- Rust
- Stars
- 39.1k
- Forks
- 1.9k
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 4
Description
## Specific Demand
Iterating through the Children of a component is very complex currently, for instance:
```rs
#![allow(non_snake_case)]
use dioxus::prelude::*;
#[derive(Props)]
pub struct BreadcrumbsProps<'a> {
divider: Option<&'a str>,
children: Vec>
}
pub fn Breadcrumbs<'a>(cx: Scope<'a, BreadcrumbsProps<'a>>) -> Element {
cx.render(rsx!(
nav {
role: "navigation",
for child in &cx.props.children {
span {
p { cx.props.divider.unwrap_or("->") }
child
}
}
}
))
}
#[derive(PartialEq, Props)]
pub struct BreadcrumbProps<'a> {
name: &'a str,
link: &'a str
}
pub fn Breadcrumb<'a>(cx: Scope<'a, BreadcrumbProps<'a>>) -> Element {
cx.render(rsx!(
a {
href: cx.props.link,
cx.props.name
}
))
}
```
So this should be consumable like so:
```
Breadcrumbs {
divider: "/",
Breadcrumb {
name: "Level 1",
link: "/"
}
Breadcrumb {
name: "Level 2",
link: "/level2"
}
}
```
Additional context: https://discord.com/channels/899851952891002890/1127735881076330548
## Implement Suggestion
The syntax for such implementation is not very straight forward, making the DX very poor implementing components like this. Either this should be made easier, or a better approach should be documented on how to best tackle this issue with code examples.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.