Expand description
§Dioxus Fullstack Core
Dioxus-fullstack-core provides types, traits, hooks, contexts for dioxus-fullstack. Libraries that need to integrate with dioxus-fullstack should rely on this crate instead of the full-fledged renderer for quicker build times.
§Usage
To start using this crate, you can run the following command:
cargo add dioxus-fullstack-hooksThen you can use hooks like use_server_future in your components:
use dioxus::prelude::*;
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()}"
}
}
async fn fetch_article(id: u32) -> String {
format!("Article {}", id)
}Re-exports§
Modules§
- document
- On the client, we use the
FullstackWebDocumentimplementation to render the head for any elements that were not rendered on the server. - error
- Error types and utilities.
- history
- A history provider for fullstack apps that is compatible with hydration.
- httperror
Structs§
- Fullstack
Context - The context provided by dioxus fullstack for server-side rendering.
- Fullstack
Context Inner - Hydration
Context - Data shared between the frontend and the backend for hydration of server functions.
- Loader
- A Loader is a signal that represents a value that is loaded asynchronously.
- Loader
Handle - Serialize
Context Entry - An entry into the serialized context. The order entries are created in must be consistent between the server and the client.
- Serialized
Hydration Data - Data that was serialized on the server for hydration on the client. This includes extra information about the types and sources of the serialized data in debug mode
Enums§
- Loader
State - Loading
- Streaming
Status - The status of the streaming response
- Take
Data Error - An error that can occur when trying to take data from the server
Traits§
- Transportable
- A
Transportabletype can be safely transported from the server to the client, and be used for hydration. Not all types can sensibly be transported, but many can. This trait makes it possible to customize how types are transported which helps for non-serializable types likedioxus_core::CapturedError.
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.
- extract
Deprecated - Extract an axum extractor from the current request.
- head_
element_ hydration_ entry - Create a new entry in the serialize context for the head element hydration
- init_
error_ boundary - Initializes an error boundary context that is compatible with hydration.
- is_
hydrating - Check if the client is currently rendering a component for hydration. Always returns true on the server.
- serialize_
context - Get or insert the current serialize context. On the client, the hydration context this returns
will always return
TakeDataError::DataNotAvailableif hydration of the current chunk is finished. - status_
code_ from_ error - Convert a
CapturedErrorinto an appropriate HTTP status code. - use_
loader - A hook to create a resource that loads data asynchronously.
- use_
server_ cached - This allows you to send data from the server to the client during hydration.
- 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.