dioxus/examples/drops.rs

37 lines
577 B
Rust
Raw Normal View History

2023-01-15 18:02:24 +00:00
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let count = if cx.generation() % 2 == 0 { 10 } else { 0 };
println!("Generation: {}", cx.generation());
if cx.generation() < 10 {
cx.needs_update();
}
render! {
(0..count).map(|_| rsx!{
2023-01-15 18:12:22 +00:00
drop_child {}
2023-01-15 18:02:24 +00:00
})
}
}
2023-01-15 18:12:22 +00:00
fn drop_child(cx: Scope) -> Element {
2023-01-15 18:02:24 +00:00
cx.use_hook(|| Drops);
render! {
div{}
}
}
struct Drops;
impl Drop for Drops {
fn drop(&mut self) {
println!("Dropped!");
}
}