Skip to content

Components

AsyncState: every data view has four states

AsyncState renders a view that loads data as exactly one of four things: loading, an error with a way to try again, empty, or the content. Every list and record in an app built on Meadowstack goes through it, so no screen shows a blank page, an endless spinner or a crash when the network fails.

By Bohuslav PoláčekChecked

Kestrel's invoice list in four states, rendered from the kit: loading, an error with a retry, empty with the action that creates the first invoice, and no results for a filter with the way out. The resource is set to each status by hand, the way useResource returns it.

What it is for, and what the preview shows

AsyncState takes the resource that useResource() returns and renders one branch of it: the loading element while the data loads, an error with a retry when it fails, the empty element when isEmpty says there is nothing, and its children with the data when it succeeds. A list adds one more case inside the content: DataTable tells a list that is empty because nothing exists yet from one that a filter emptied.

The preview is the invoice list of Kestrel, an accounting practice in the demo, in each state: a skeleton with the table's frame while invoices load, the kit's error with a button to try again, the empty list with the action that creates the first invoice, and a filter with no results that offers to clear it. As in Kestrel's code, the two empty states come from the table inside AsyncState's content; AsyncState's own empty branch is for views without a table.

The rules, and where each one lives

  • Four states for every data view. Load with useResource() and render through AsyncState (the root AGENTS.md, Every data view has four states). npm run check:states fails a screen that calls useResource() without it, because that screen goes blank when the network fails.
  • Empty and no results are different. Two states with two next steps: empty offers to create the first record, no results offers to clear the filter (AGENTS.md; docs/patterns.md).
  • Skeletons only on first load. After a save the screen stays and the data swaps quietly; a skeleton shows only on the first load or for a new filter, with the content's frame and widths (AGENTS.md, Lightness).
  • No wall in the demo. The runtime audit's no-wall fails a demo route where the default visitor meets an empty view ([data-state="empty"]); a filter with no results (data-state="no-results") is fine (docs/audit.md).
  • Null means nothing. loading={null} renders nothing while the data loads: the fallbacks are compared with undefined, so a small inline use, such as a count in the sidebar, never draws a full-width skeleton (the manifest's summary).

What AI coding tools write instead

The manifest's replaces: if-loading and if-error branches written by hand, and a hand-built empty state. Asked for a list, an assistant writes if (loading) return <Spinner />, leaves the error out until the first failure, and renders an empty table when the array is empty.

Every screen then handles the states a little differently. One spinner sits in the middle of the page, another shifts the layout when the data lands, an error shows a raw message with no way to retry, and an empty list looks the same as a filter with no results, so people cannot tell whether nothing exists or their filter hid it. With AsyncState and DataTable the assistant writes the content and the two empty states, and check:states catches a screen that skips them.

How to use it

The props, from its exported AsyncStateProps<T>:

  • resource: what useResource() returns: loading, an error, or the data.
  • children: a function of the data that renders the content.
  • loading: the skeleton, such as LoadingState with rows and a label; null renders nothing.
  • onRetry: the kit's error with a button that calls it, usually the resource's reload; or error, a function of the error and the retry for a view's own error.
  • isEmpty and empty: for a view without a table, when its data counts as empty and what to show then.

Inside the content, a DataTable takes emptyState, isFiltered and onClearFilters for the two empty states of a list. The pattern behind both is data states.

Its entry in the manifest

The component's rules as the kit's manifest states them, the same entry an AI coding tool reads.Read from the kit's component manifest when the site was built (126 components, packages/kit/src/components.json); the same entry answers an AI coding tool through the kit's MCP server.

Where it runs in the example apps

The example apps whose code renders AsyncState, and in which modules, read from the demo's source.Read from the demo's source when the site was built: 9 of 9 example apps render <AsyncState>, in the modules named here as each app's sidebar names them.

How the starter loads a request

templates/starter/src/modules/requests/components/request-record.tsx
<AsyncState
  resource={record.resource}
  onRetry={record.reload}
  loading={frame(<RecordSkeleton />)}
  error={(error, retry) => frame(<RecordError error={error} retry={retry} action={errorAction} />)}
>
  {(data) => (
    <RequestRecordView
      {...data}
      variant={variant}
      collapse={collapse}
      onChange={record.setData}
      onSaved={onSaved}
      onDeleted={onDeleted}
    />
  )}
</AsyncState>
The starter's purchase request: retry from the resource's own reload, a skeleton and an error inside the panel's frame, and the record's view once the data is there.

Questions

What is the difference between empty and no results?

Empty means nothing exists yet, so the next step creates the first record. No results means a filter hid everything, so the next step clears the filter. DataTable draws them as two states.

Does a save show the loading state again?

No. After a save the screen stays and the data swaps quietly. The skeleton shows only on the first load, or when a new filter loads new data.

How do I render nothing while something small loads?

Pass null as loading. AsyncState compares its fallbacks with undefined, so null means render nothing, which suits a count in the sidebar.

What does the error state offer?

A short message and a button to try again, which calls the resource's reload. A view can pass its own error element, which receives the error and the retry.

Is there a check that every view has its states?

Yes. npm run check:states, one of the fast checks, fails a screen that loads data with useResource and does not render it through AsyncState.

Two ways

Build it yourself, or have it built

  • Build it yourself

    Build your app on the framework

    Get the codebase these apps stand on and build yours with Claude Code, Cursor or Codex.

    One payment, lifetime updates

    Get the framework
  • Have it built

    Have us build your app

    Tell us how your team works. We plan the app with you and build it on the same framework at a fixed price.

    After launch, Care keeps it improving, from €99 a month.

    from €1,990

    Describe your app