Loading, error, empty and no results
A view that loads data is always in one of four states: loading, an error with a way to try again, empty, or showing the data, and a filter that matches nothing is a different state from empty, with a different next step. In Meadowstack a screen loads through `useResource()` and renders through `<AsyncState>`, which draws exactly one state at a time, and `npm run check:states` fails any page that loads data without it.
By Bohuslav PoláčekChecked
<AsyncState resource={resource} onRetry={reload} loading={<LoadingState rows={8} label="Loading requests…" />}>
{() => (
<DataTable
label="Purchase requests"
columns={columns}
data={rows}
getRowId={(item) => item.id}
getRowLabel={(item) => `${item.title}, ${item.number}`}
enableSelection
onSelectionChange={(ids) => setSelection({ key: selectionKey, ids })}
selectionResetKey={selectionKey}
onRowClick={(item) => openPeek(item.id)}
activeRowId={peekId ?? undefined}
onVisibleRowsChange={setVisibleIds}
pageSize={25}
isFiltered={isFiltered}
onClearFilters={() => {
setSearch("");
setParams(
(current) => {
const next = new URLSearchParams(current);
next.delete(keys.status);
next.delete(keys.search);
return next;
},
{ replace: true },
);
}}
emptyState={emptyState}
/>
)}
</AsyncState>The flow, step by step
What a person meets on the starter's purchase request list, and how to call up each state yourself:
- First load. A skeleton in the shape of the table, eight rows with the content's widths, so nothing jumps when the data arrives. Moving between pages in the demo shows a thin line at the top (
RouteProgress), never a spinner over the whole page. Add?latency=slowto the address to watch it for 1600ms. - The server fails. The skeleton gives way to a sentence that says what failed and a "Try again" button, which loads the data again and nothing else.
?fail=1makes every request fail. - Nothing yet. An empty list says so and offers the first step: "No purchase requests yet", with New request for people who may create one.
?empty=1empties every list. - Nothing matches. A filter or a search that hides every row is a different state: it says nothing matches and offers to clear the filters. The filters live in the address, so Back undoes them too.
- A change. Approving a request changes its row at once and the toast offers Undo. When the api answers, the server's version (a new history entry, real ids) swaps in quietly, never through the loading state. When it refuses, the screen goes back to what is stored and the toast says why.
- Two quick changes. Approve, then Undo before the first answer lands. Each change takes a turn, only the newest answer is written, and the screen ends where the last click left it.
In the demo, the account menu's "For developers" part switches any screen, the task board included, to a slow network, failing requests or empty data.
The rules and where each one is enforced
| Rule | Where it is enforced |
|---|---|
| Every view that loads data draws all four states | useResource() and <AsyncState>; npm run check:states fails a screen that calls useResource() without <AsyncState> |
| Loading is a skeleton in the content's shape | the kit's LoadingState, Skeleton and ChartSkeleton, and AsyncState's default for a branch you do not pass |
| An error says what failed and how to try again | ErrorState with onRetry, which AsyncState passes on |
| Empty and no results are different states | DataTable's isFiltered, onClearFilters and emptyState; starter e2e "filters live in the address, and empty, no results and errors each say what to do" |
| The demo's default visitor never meets an empty view | the audit's no-wall rule in docs/audit.md: no data-state="empty" and no NoAccess on any route, while data-state="no-results" is fine |
| A reload of the same data keeps it on screen | useResource's reload(); new dependencies, another filter or another record, show the loading state |
| A save swaps in the server's truth quietly | setData(() => fresh) when the change is still the newest, never reload() after a save (.claude/rules/apps.md) |
| A change after an await builds on the data on screen | setData((current) => …), a rule in the root AGENTS.md |
| The newest answer of a record wins | useTurns() in shared/use-turns.ts |
| Every state can be called up on demand | ?latency=slow, ?fail=1 and ?empty=1 in the starter, read once when the page loads; the demo's "For developers" menu |
What AI coding tools build instead
- A fetch in
useEffectwith a loading flag. There is no error branch, so when the request fails the spinner turns for ever or the screen stays blank, and there is no cancellation, so an old answer overwrites a newer filter. This is the bugcheck:statesexists for. - One "No data" for everything. An empty list and a filter that matches nothing say the same thing, and the person who filtered wonders where their records went.
- A spinner in the middle of the page instead of a skeleton. It says nothing about what is coming, and the layout jumps when the data lands.
reload()after every save. The skeleton flashes over data the person was working with, and a picker they had opened meanwhile vanishes with it.setData(valueBuiltBefore)after an await. The answer lands and puts back the screen as it was before the second click.- An optimistic change with no failure path. The screen keeps a change the server refused.
- Tests for the success state only. The other three are where the bugs are.
Where to see it
- Task board: a card moves at once and the toast offers Undo.
- Bank reconciliation: pairing a payment applies at once, with Undo.
- Document inbox: a filtered list with its no-results state.
- The kit's AsyncState and DataTable, the list that shows all four states, and the approval flow, whose moves are the optimistic changes above.
Example apps that draw their states through AsyncState
| 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 |
The check that fails a page without states
const problems = [];
for (const file of scanDirs.flatMap((dir) => walk(dir))) {
const source = readFileSync(file, "utf8");
if (/\buseResource\s*\(/.test(source) && !/<AsyncState\b/.test(source) && !file.endsWith("use-resource.ts")) {
problems.push(`${relative(root, file)} loads data with useResource() but never renders <AsyncState>.`);
}
}
if (problems.length) {
for (const p of problems) console.error(p);
console.error(`\nState check failed: ${problems.length} screen(s) without loading, error and empty states.`);
process.exit(1);
}
console.log("State check passed.");Questions
What is the difference between an empty state and a no-results state?
Empty means nothing exists yet, and it offers the first step, such as New request. No results means a filter or a search hides everything, and it offers to clear the filters. One sentence for both leaves the person who filtered looking for records that are still there.
Should I show a spinner or a skeleton while data loads?
A skeleton in the shape of what is coming, on the first load and when a filter changes. A spinner says nothing about what is coming and the layout jumps when the data arrives. After a save, neither: the data swaps in quietly.
How do I see the error and empty states without breaking the server?
In the starter, add ?fail=1, ?empty=1 or ?latency=slow to the address; the flags are read once when the page loads. In the demo, the account menu's For developers part switches the same three on any screen.
What happens when two changes overlap on a slow network?
Each change takes a turn when it starts, and only the newest answer is written onto the screen. Approve, then Undo before the first answer lands, and the screen ends where the last click left it.
Does the check catch every screen without states?
It catches every screen that loads data through useResource() and never renders AsyncState. A screen that fetches some other way breaks a different rule of the framework: no data loading in an effect outside useResource.
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