tostring.rs 640 B

12345678910111213141516171819202122232425
  1. use dioxus::prelude::*;
  2. use dioxus::ssr;
  3. pub static Example: FC<()> = |cx| {
  4. let as_string = use_state(cx, || {
  5. // Currently, SSR is only supported for whole VirtualDOMs
  6. // This is an easy/low hanging fruit to improve upon
  7. let mut dom = VirtualDom::new(SomeApp);
  8. dom.rebuild_in_place().unwrap();
  9. ssr::render_vdom(&dom)
  10. });
  11. cx.render(rsx! {
  12. div { "{as_string}" }
  13. })
  14. };
  15. static SomeApp: FC<()> = |cx| {
  16. cx.render(rsx! {
  17. div { style: {background_color: "blue"}
  18. h1 {"Some amazing app or component"}
  19. p {"Things are great"}
  20. }
  21. })
  22. };