allow passing props to the rendered component

This commit is contained in:
Evan Almloff committed 2023-03-30 19:42:46 -05:00
1 parent 39a5fbf268
commit f618da7311
6 files changed
+19 -10

No files matched your search

+2
View File
@@ -1,2 +1,4 @@
#[cfg(feature = "axum")]
pub mod axum_adapter;
#[cfg(feature = "salvo")]
pub mod salvo_adapter;
+5 -2
View File
@@ -9,6 +9,8 @@ mod server_fn;
pub mod prelude {
#[cfg(feature = "axum")]
pub use crate::adapters::axum_adapter::*;
#[cfg(feature = "salvo")]
pub use crate::adapters::salvo_adapter::*;
#[cfg(feature = "ssr")]
pub use crate::serve::ServeConfig;
pub use crate::server_fn::{DioxusServerContext, ServerFn};
@@ -17,7 +19,7 @@ pub mod prelude {
}
#[cfg(feature = "ssr")]
fn dioxus_ssr_html(cfg: serve::ServeConfig) -> String {
fn dioxus_ssr_html<P: 'static + Clone>(cfg: &serve::ServeConfig<P>) -> String {
use prelude::ServeConfig;
let ServeConfig {
@@ -25,12 +27,13 @@ fn dioxus_ssr_html(cfg: serve::ServeConfig) -> String {
application_name,
base_path,
head,
props,
..
} = cfg;
let application_name = application_name.unwrap_or("dioxus");
let mut vdom = VirtualDom::new(app);
let mut vdom = VirtualDom::new_with_props(*app, props.clone());
let _ = vdom.rebuild();
let renderered = dioxus_ssr::pre_render(&vdom);
let base_path = base_path.unwrap_or(".");
+6 -4
View File
@@ -1,19 +1,21 @@
use dioxus_core::Component;
#[derive(Clone)]
pub struct ServeConfig {
pub(crate) app: Component,
pub struct ServeConfig<P: Clone> {
pub(crate) app: Component<P>,
pub(crate) props: P,
pub(crate) application_name: Option<&'static str>,
pub(crate) server_fn_route: Option<&'static str>,
pub(crate) base_path: Option<&'static str>,
pub(crate) head: Option<&'static str>,
}
impl ServeConfig {
impl<P: Clone> ServeConfig<P> {
/// Create a new ServeConfig
pub fn new(app: Component) -> Self {
pub fn new(app: Component<P>, props: P) -> Self {
Self {
app,
props,
application_name: None,
server_fn_route: None,
base_path: None,
+1
View File
@@ -1,3 +1,4 @@
#[derive(Clone)]
pub struct DioxusServerContext {}
#[cfg(any(feature = "ssr", doc))]