Crate dioxus_fullstack_core

Crate dioxus_fullstack_core 

Source
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-hooks

Then 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§

pub use error::*;
pub use httperror::*;

Modules§

document
On the client, we use the FullstackWebDocument implementation 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§

FullstackContext
The context provided by dioxus fullstack for server-side rendering.
FullstackContextInner
HydrationContext
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.
LoaderHandle
SerializeContextEntry
An entry into the serialized context. The order entries are created in must be consistent between the server and the client.
SerializedHydrationData
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§

LoaderState
Loading
StreamingStatus
The status of the streaming response
TakeDataError
An error that can occur when trying to take data from the server

Traits§

Transportable
A Transportable type 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 like dioxus_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.
extractDeprecated
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::DataNotAvailable if hydration of the current chunk is finished.
status_code_from_error
Convert a CapturedError into 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.