FutureBuilder

FutureBuilder renders from the latest snapshot of one asynchronous job. Use it for declared one-shot loads such as products, a profile, or an import preview. Do not declare a save resource merely because a document rendered: a user-requested mutation belongs behind an explicit action and effect.
The resource is declared during component conversion. Reducers still own the state changes when the job succeeds or fails.

Basic shape

use fission::prelude::*;

// Inside the catalog parent's Compose view setup block:
let request = state.product_request();
let loaded = cx.bind(ProductsLoaded, reduce!(on_products_loaded));
let failed = cx.bind(ProductsFailed, reduce!(on_products_failed));
let products = FutureBuilder::new(
    ResourceKey::new("catalog.products"),
    PRODUCTS_JOB,
    request.clone(),
    state.products.clone(),
    |_ctx, _view, snapshot| {
        ProductList {
            snapshot: snapshot.clone(),
        }
        .into()
    },
)
.deps(request)
.on_ok(loaded)
.on_err(failed);

// Use products as an ordinary Rust expression in the parent Compose tree.
This is a resource declaration excerpt, not a complete catalog application. The parent defines product_request, PRODUCTS_JOB, the snapshot field, completion reducers, and the named ProductList component. A custom component with required props can be constructed by the fully specified Rust literal shown here without relying on a nonexistent Default implementation.
The important rule is that the snapshot is not hidden inside the widget. Store it in your app state. The success and error reducers update that state, and the next build renders the new snapshot.

Field table

Field
Type
Meaning
Notes / default behavior
key
ResourceKey
Stable identity for this job resource.
Keep it stable for the logical resource, not for a single frame.
job
JobRef<J>
The registered job to run.
The shell must register a handler for the job.
request
J::Request
Request payload passed to the job.
Cloneable request value.
snapshot
AsyncSnapshot<J::Ok, J::Err>
Current app-owned loading/data/error state.
Reducers update it after job callbacks.
on_ok
Option<ActionEnvelope>
Action dispatched when the job succeeds.
Use this to bind the success reducer.
on_err
Option<ActionEnvelope>
Action dispatched when the job fails.
Use this to bind the error reducer.
deps
Option<Vec<u8>>
Serialized dependency identity.
Changing deps restarts or preserves according to policy.
policy
ResourcePolicy
How resource changes are handled.
Defaults to RestartOnChange.
builder
AsyncWidgetBuilder<S, J::Ok, J::Err>
Pure closure that turns the current snapshot into UI.
Keep the closure small; delegate real UI to a named component that receives the snapshot.

Snapshot states

AsyncSnapshot has three pieces: a connection state, optional data, and optional error.
Represent a pending request with AsyncSnapshot::waiting(); the application must not reset a completed snapshot to waiting on every build. Use AsyncSnapshot::with_data(AsyncConnectionState::Done, value) when it succeeds. Use AsyncSnapshot::with_error(AsyncConnectionState::Done, error) when it fails. The helper methods data(), error(), has_data(), and has_error() make display widgets straightforward.

Production checklist

•
Test waiting, data, empty, error, changed dependencies, and disposal.
•
Register both completion paths and reject stale results where requests can overlap.
•
Keep mutations behind explicit actions instead of triggering them through rendering.