feat: add more to ssr renderer

This commit is contained in:
Jonathan Kelley committed 2021-10-18 12:53:56 -04:00
1 parent f49244344c
commit 63568c546c
3 files changed
+80 -9

No files matched your search

+19 -2
View File
@@ -14,7 +14,7 @@ let mut vdom = VirtualDOM::new(App);
let _ = vdom.rebuild();
// Render the entire virtualdom from the root
let text = dioxus_ssr::render_vdom(&vdom, |c| c);
let text = dioxus::ssr::render_vdom(&vdom, |c| c);
assert_eq!(text, "<div>hello world!</div>")
```
@@ -40,12 +40,29 @@ let text = dioxus::ssr::render_vdom(App, |cfg| cfg.pre_render(true));
Dioxus SSR can also be to render on the server. Obviously, you can just render the VirtualDOM to a string and send that down.
```rust
let text = dioxus_ssr::render_vdom(&vdom, |c| c);
let text = dioxus::ssr::render_vdom(&vdom, |c| c);
assert_eq!(text, "<div>hello world!</div>")
```
The rest of the space - IE doing this more efficiently, caching the virtualdom, etc, will all need to be a custom implementation for now.
## Usage without a VirtualDom
Dioxus SSR needs an arena to allocate from - whether it be the VirtualDom or a dedicated Bump allocator. To render `rsx!` directly to a string, you'll want to create an `SsrRenderer` and call `render_lazy`.
```rust
let text = dioxus::ssr::SsrRenderer::new().render_lazy(rsx!{
div { "hello world" }
});
assert_eq!(text, "<div>hello world!</div>")
```
This can be automated with the `render_lazy!` macro:
```rust
let text = render_lazy!(rsx!( div { "hello world" } ));
```
## Usage in static site generation
Dioxus SSR is a powerful tool to generate static sites. Using Dioxus for static site generation _is_ a bit overkill, however. The new documentation generation library, Doxie, is essentially Dioxus SSR on steroids designed for static site generation with client-side hydration.