# 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.

Checked 2 December 2026. By Bohuslav Poláček. https://meadowstack.com/components/async-state/

*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.*

A live screen, rendered from the kit's components on the page: https://meadowstack.com/components/async-state/

## 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](https://meadowstack.com/components/data-table/) tells a list that is empty because nothing exists yet from one that a filter emptied.

The preview is the invoice list of [Kestrel](https://meadowstack.com/examples/accounting-office-documents/), 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](https://meadowstack.com/patterns/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.*

| Manifest field | AsyncState |
| --- | --- |
| What it is | Renders exactly one of: loading, error, empty, content. Fallbacks are compared with undefined, not `??`: `loading={null}` means "render nothing", which small inline uses (sidebar counts) rely on. With `??` a null fell through to the full-width skeleton and drew it over the nav. |
| Use it for | Every view that loads data with useResource: loading, error with retry, empty, content. |
| Not for | For data that is already there |
| It replaces | If loading and if error branches by hand; A hand-built empty state |
| Screen types | Any |
| Import | `import { AsyncState, EmptyState, ErrorState, LoadingState } from "@meadowstack-studio/kit";` |

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.*

| Example app | Modules that render it |
| --- | --- |
| [An app for a packaging and print company](https://meadowstack.com/examples/packaging-print-production/) | Jobs, Print file editor, Quotes, Cutting dies, Colour |
| [An app for a studio or agency](https://meadowstack.com/examples/agency-capacity-planning/) | Capacity, Tasks, Time, Finance, Channels |
| [An app for a haulage company](https://meadowstack.com/examples/haulage-dispatch-planning/) | Freight, Drivers, Costs, Reports |
| [An app for a roastery with an online shop](https://meadowstack.com/examples/coffee-roastery-production/) | Roasting, Green coffee, Shop, Wholesale, Scenarios |
| [An app for a sports club](https://meadowstack.com/examples/sports-club-court-bookings/) | Front desk, Courts, Club, Coaching, Rentals |
| [An app for a construction company](https://meadowstack.com/examples/construction-site-management/) | Sites, Schedule, Crews, Machines, Site diary, Drawings, Foreman's phone, Budget |
| [An app for an accounting office](https://meadowstack.com/examples/accounting-office-documents/) | Documents, Bookkeeping, Official mail, Invoicing |
| [An app for restaurants and venues](https://meadowstack.com/examples/restaurant-staff-rota/) | Shifts, Kitchen, Food safety, People, Handbook |
| [An app for one person](https://meadowstack.com/examples/personal-app-for-a-creator/) | Brand deals, Content, Money, Training |

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

*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.*

From `templates/starter/src/modules/requests/components/request-record.tsx` in the Meadowstack repository:

```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>
```

## 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.

## Related

- [Loading, error, empty and no results](https://meadowstack.com/patterns/data-states/) (Patterns)
- [A weekly timesheet for an agency](https://meadowstack.com/screens/timesheet/) (Screens)
- [BulkBar: what to do with the selection](https://meadowstack.com/components/bulk-bar/) (Components)
- [DataTable: the table of every list](https://meadowstack.com/components/data-table/) (Components)
- [FilterBar: the one row above a list](https://meadowstack.com/components/filter-bar/) (Components)
- [ViewPills: saved views that are addresses](https://meadowstack.com/components/view-pills/) (Components)
