Expand description
§Dioxus Fullstack Hooks
Dioxus fullstack hooks provides hooks and contexts for dioxus-fullstack
. Libraries that need to integrate with dioxus-fullstack should rely on this crate instead of the renderer for quicker build times.
§Usage
To start using this crate, you can run the following command:
cargo add dioxus-fullstack-hooks
Then you can use hooks like use_server_future
in your components:
use dioxus::prelude::*;
async fn fetch_article(id: u32) -> String {
format!("Article {}", id)
}
fn App() -> Element {
let mut article_id = use_signal(|| 0);
// `use_server_future` will spawn a task that runs on the server and serializes the result to send to the client.
// The future will rerun any time the
// Since we bubble up the suspense with `?`, the server will wait for the future to resolve before rendering
let article = use_server_future(move || fetch_article(article_id()))?;
rsx! {
"{article().unwrap()}"
}
}
Structs§
- Streaming
Context - The context dioxus fullstack provides for the status of streaming responses on the server
Enums§
- Streaming
Status - The status of the streaming response
Functions§
- commit_
initial_ chunk - Commit the initial chunk of the response. This will be called automatically if you are using the dioxus router when the suspense boundary above the router is resolved. Otherwise, you will need to call this manually to start the streaming part of the response.
- current_
status - Get the current status of the streaming response. This method is reactive and will cause the current reactive context to rerun when the status changes.
- use_
server_ cached - 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.
- use_
server_ future - Runs a future with a manual list of dependencies and returns a resource with the result if the future is finished or a suspended error if it is still running.