2021-07-11 18:49:52 +00:00
|
|
|
# Dioxus SSR
|
|
|
|
|
|
|
|
Render a Dioxus VirtualDOM to a string.
|
|
|
|
|
|
|
|
```rust
|
|
|
|
// Our app:
|
2021-09-21 17:42:52 +00:00
|
|
|
const App: FC<()> = |cx, props|cx.render(rsx!(div {"hello world!"}));
|
2021-07-11 18:49:52 +00:00
|
|
|
|
|
|
|
// Build the virtualdom from our app
|
|
|
|
let mut vdom = VirtualDOM::new(App);
|
|
|
|
|
|
|
|
// This runs components, lifecycles, etc. without needing a physical dom. Some features (like noderef) won't work.
|
|
|
|
vdom.rebuild_in_place();
|
|
|
|
|
|
|
|
// Render the entire virtualdom from the root
|
|
|
|
let text = dioxus_ssr::render_root(&vdom);
|
|
|
|
assert_eq!(text, "<div>hello world!</div>")
|
|
|
|
```
|
2021-07-29 01:46:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Pre-rendering
|
|
|
|
|
|
|
|
|