Learn Fate

Decide where data loads

Chapter 3 of 6

Imagine the reading tracker now opens a book stored on a server. The screen should request the title and any fields its children need. The child components resolve their own views against the resulting references.

This is the shape of a screen request after wiring a transport and registering a book root. BookView is a view defined against the entity type for that backend.

const { book } = useRequest(
  { book: { id: bookId, view: BookView } },
  { mode: 'stale-while-revalidate' },
);

Match the request mode to the screen

ModeWhen to use it
cache-firstDefault. Reuse fresh cached data and request missing or stale selections.
stale-while-revalidateShow the cached shelf immediately when available and refresh it in the background.
network-onlyFetch from the server for this read.
cache-onlyInspect what is already available without fetching. Handle missing data in the UI.

Put a Suspense boundary around the parts of the screen that can wait together. A first load can show “Loading book…”. A known missing book needs its own message. An error boundary handles thrown read failures and can offer a retry.

Try it

In the local tracker, change the root request to cache-only. Pass the optional reference to useView before branching on its return value, as in the client state example. The schema can supply the tracker’s local fields. For a server-backed reading list, try the same mode with an empty cache, then after a successful fetch, and compare the results.

Choose a backend when you need one

Use Fate’s server integration for native HTTP or tRPC, or follow the GraphQL integration for an existing GraphQL schema. Keep access checks and input validation on the server.

Request modes and preloading