mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-30 08:00:21 +00:00
50 lines
911 B
Rust
50 lines
911 B
Rust
#![allow(non_snake_case)]
|
|
|
|
use dioxus::prelude::*;
|
|
|
|
fn main() {
|
|
launch(app);
|
|
}
|
|
|
|
fn app() -> Element {
|
|
let mut vec = use_signal(|| vec![0]);
|
|
|
|
rsx! {
|
|
button {
|
|
onclick: move |_| {
|
|
let mut write = vec.write();
|
|
let len = write.len() as i32;
|
|
write.push(len);
|
|
},
|
|
"Create"
|
|
}
|
|
|
|
button {
|
|
onclick: move |_| {
|
|
vec.write().pop();
|
|
},
|
|
"Destroy"
|
|
}
|
|
|
|
for i in 0..vec.len() {
|
|
Child { count: vec.map(move |v| &v[i]) }
|
|
}
|
|
}
|
|
}
|
|
|
|
#[component]
|
|
fn Child(count: MappedSignal<i32>) -> Element {
|
|
use_memo({
|
|
to_owned![count];
|
|
move || {
|
|
let value = count.read();
|
|
println!("Child value: {value}");
|
|
}
|
|
});
|
|
|
|
rsx! {
|
|
div {
|
|
"Child: {count}"
|
|
}
|
|
}
|
|
}
|