simple_list.rs 1014 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. //! A few ways of mapping elements into rsx! syntax
  2. //!
  3. //! Rsx allows anything that's an iterator where the output type implements Into<Element>, so you can use any of the following:
  4. use dioxus::prelude::*;
  5. fn main() {
  6. dioxus::launch(app);
  7. }
  8. fn app() -> Element {
  9. rsx!(
  10. div {
  11. // Use Map directly to lazily pull elements
  12. {(0..10).map(|f| rsx! { "{f}" })}
  13. // Collect into an intermediate collection if necessary, and call into_iter
  14. {["a", "b", "c", "d", "e", "f"]
  15. .into_iter()
  16. .map(|f| rsx! { "{f}" })
  17. .collect::<Vec<_>>()
  18. .into_iter()}
  19. // Use optionals
  20. {Some(rsx! { "Some" })}
  21. // use a for loop where the body itself is RSX
  22. for name in 0..10 {
  23. div { "{name}" }
  24. }
  25. // Or even use an unterminated conditional
  26. if true {
  27. "hello world!"
  28. }
  29. }
  30. )
  31. }