فهرست منبع

document from_server

Evan Almloff 1 سال پیش
والد
کامیت
040b9d15a8
2فایلهای تغییر یافته به همراه19 افزوده شده و 3 حذف شده
  1. 1 1
      packages/fullstack/src/lib.rs
  2. 18 2
      packages/fullstack/src/use_server/mod.rs

+ 1 - 1
packages/fullstack/src/lib.rs

@@ -60,5 +60,5 @@ pub mod prelude {
     pub use dioxus_ssr::incremental::IncrementalRendererConfig;
     pub use server_fn::{self, ServerFn as _, ServerFnError};
 
-    pub use use_server::server_cached;
+    pub use use_server::from_server;
 }

+ 18 - 2
packages/fullstack/src/use_server/mod.rs

@@ -1,7 +1,23 @@
 use serde::{de::DeserializeOwned, Serialize};
 
-/// TODO: Document this
-pub fn server_cached<O: 'static + Serialize + DeserializeOwned>(server_fn: impl Fn() -> O) -> O {
+/// This allows you to send data from the server to the client. The data is serialized into the HTML on the server and hydrated on the client.
+///
+/// When you run this function on the client, you need to be careful to insure the order you run it initially is the same order you run it on the server.
+///
+/// If Dioxus fullstack cannot find the data on the client, it will run the closure again to get the data.
+///
+/// # Example
+/// ```rust
+/// use dioxus::prelude::*;
+/// use dioxus_fullstack::prelude::*;
+///
+/// fn app(cx: Scope) -> Element {
+///    let state1 = use_state(cx, || from_server(|| {
+///       1234
+///    }));
+/// }
+/// ```
+pub fn from_server<O: 'static + Serialize + DeserializeOwned>(server_fn: impl Fn() -> O) -> O {
     #[cfg(feature = "ssr")]
     {
         let data =