rsx_compile_fail.rs 1.3 KB

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