-
Hi I have been playing around with leptos and loved the Is there a way to enable hydration/ssr for it? Am I missing something? Bellow is sample code for what I am trying to do: #[component]
pub fn MonthlyView(
cx: Scope,
data: RwSignal<Option<Result<Vec<(NaiveDate, Vec<String>)>, ServerFnError>>>,
) -> impl IntoView {
// ...
}
// This included in the Router
#[component]
pub fn TestPage(cx: Scope) -> impl IntoView {
let today = chrono::Utc::now().naive_utc().date();
let test_action = create_server_action::<GetMonthlyView>(cx);
// MonthlyView IS EMPTY until this runs(or user submits a request)
test_action.dispatch(GetMonthlyView {
year: today.year() as u32,
month: today.month(),
});
view! { cx,
<YearMonthInput action=test_action/>
<MonthlyView data=test_action.value()/>
}
} The |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
If you ever find yourself creating an action and immediately dispatching it, you should probably be using a resource instead. If you used a resource to load the data here, it would load on the server and stream down to the client. Any data you used from it in your view behind a Suspense or Transition would appear in the HTML before the WASM had loaded. You could then use a |
Beta Was this translation helpful? Give feedback.
If you ever find yourself creating an action and immediately dispatching it, you should probably be using a resource instead. If you used a resource to load the data here, it would load on the server and stream down to the client. Any data you used from it in your view behind a Suspense or Transition would appear in the HTML before the WASM had loaded.
You could then use a
create_effect
andResource::set
to feed the action's value into the resource.