1
0

drops.rs 577 B

123456789101112131415161718192021222324252627282930313233343536
  1. use dioxus::prelude::*;
  2. fn main() {
  3. dioxus_desktop::launch(app);
  4. }
  5. fn app(cx: Scope) -> Element {
  6. let count = if cx.generation() % 2 == 0 { 10 } else { 0 };
  7. println!("Generation: {}", cx.generation());
  8. if cx.generation() < 10 {
  9. cx.needs_update();
  10. }
  11. render! {
  12. (0..count).map(|_| rsx!{
  13. drop_child {}
  14. })
  15. }
  16. }
  17. fn drop_child(cx: Scope) -> Element {
  18. cx.use_hook(|| Drops);
  19. render! {
  20. div{}
  21. }
  22. }
  23. struct Drops;
  24. impl Drop for Drops {
  25. fn drop(&mut self) {
  26. println!("Dropped!");
  27. }
  28. }