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
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 throughAsyncState(the rootAGENTS.md, Every data view has four states).npm run check:statesfails a screen that callsuseResource()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-wallfails 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: whatuseResource()returns: loading, an error, or the data.children: a function of the data that renders the content.loading: the skeleton, such asLoadingStatewithrowsand alabel;nullrenders nothing.onRetry: the kit's error with a button that calls it, usually the resource'sreload; orerror, a function of the error and the retry for a view's own error.isEmptyandempty: 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
| 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"; |
Where it runs in the example apps
| Example app | Modules that render it |
|---|---|
| An app for a packaging and print company | Jobs, Print file editor, Quotes, Cutting dies, Colour |
| An app for a studio or agency | Capacity, Tasks, Time, Finance, Channels |
| An app for a haulage company | Freight, Drivers, Costs, Reports |
| An app for a roastery with an online shop | Roasting, Green coffee, Shop, Wholesale, Scenarios |
| An app for a sports club | Front desk, Courts, Club, Coaching, Rentals |
| An app for a construction company | Sites, Schedule, Crews, Machines, Site diary, Drawings, Foreman's phone, Budget |
| An app for an accounting office | Documents, Bookkeeping, Official mail, Invoicing |
| An app for restaurants and venues | Shifts, Kitchen, Food safety, People, Handbook |
| An app for one person | Brand deals, Content, Money, Training |
How the starter loads a request
<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.
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 frameworkHave 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