rsx_compile_fail.rs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //! This example just flexes the ability to use arbitrary expressions within RSX.
  2. //! It also proves that lifetimes work properly, especially when used with use_ref
  3. use dioxus::prelude::*;
  4. fn main() {
  5. let mut vdom = VirtualDom::new(example);
  6. vdom.rebuild();
  7. let out = dioxus::ssr::render_vdom_cfg(&vdom, |c| c.newline(true).indent(true));
  8. println!("{}", out);
  9. }
  10. fn example(cx: Scope) -> Element {
  11. let items = use_state(&cx, || {
  12. vec![Thing {
  13. a: "asd".to_string(),
  14. b: 10,
  15. }]
  16. });
  17. let things = use_ref(&cx, || {
  18. vec![Thing {
  19. a: "asd".to_string(),
  20. b: 10,
  21. }]
  22. });
  23. let things_list = things.read();
  24. let mything = use_ref(&cx, || Some(String::from("asd")));
  25. let mything_read = mything.read();
  26. cx.render(rsx!(
  27. div {
  28. div {
  29. id: "asd",
  30. "your neighborhood spiderman"
  31. items.iter().cycle().take(5).map(|f| rsx!{
  32. div {
  33. "{f.a}"
  34. }
  35. })
  36. things_list.iter().map(|f| rsx!{
  37. div {
  38. "{f.a}"
  39. "{f.b}"
  40. }
  41. })
  42. mything_read.as_ref().map(|f| rsx!{
  43. div {
  44. "{f}"
  45. }
  46. })
  47. }
  48. }
  49. ))
  50. }
  51. struct Thing {
  52. a: String,
  53. b: u32,
  54. }