rsx_compile_fail.rs 1.4 KB

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