Dioxus-5.rs
· 484 B · Rust
Orginalformat
fn Counters() -> Element {
let mut counters = use_signal(|| vec![0; 10]);
rsx! {
button { onclick: move |_| counters.push(counters.len()), "Add Counter" }
ul {
for idx in 0..counters.len() {
li {
button { onclick: move |_| counters.write()[idx] += 1, "{counters.index(idx)}" }
button { onclick: move |_| { counters.remove(idx); }, "Remove" }
}
}
}
}
}
1 | fn Counters() -> Element { |
2 | let mut counters = use_signal(|| vec![0; 10]); |
3 | |
4 | rsx! { |
5 | button { onclick: move |_| counters.push(counters.len()), "Add Counter" } |
6 | ul { |
7 | for idx in 0..counters.len() { |
8 | li { |
9 | button { onclick: move |_| counters.write()[idx] += 1, "{counters.index(idx)}" } |
10 | button { onclick: move |_| { counters.remove(idx); }, "Remove" } |
11 | } |
12 | } |
13 | } |
14 | } |
15 | } |