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

Checked 2 December 2026. By Bohuslav Poláček. https://meadowstack.com/patterns/data-states/

*The starter's purchase request list: AsyncState draws the skeleton, the error with its retry or the table, and the table tells empty from no results by isFiltered. Read from the repository when the site was built.*

From `templates/starter/src/modules/requests/pages/requests-list.tsx` in the Meadowstack repository:

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

Open it in the live demo: https://meadowstack.com/demo/?lang=en#/brightpath/ukoly?pohled=tabule

## The flow, step by step

What a person meets on the starter's purchase request list, and how to call up each state yourself:

1. **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=slow` to the address to watch it for 1600ms.
2. **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=1` makes every request fail.
3. **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=1` empties every list.
4. **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.
5. **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.
6. **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 `useEffect` with 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 bug `check:states` exists 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](https://meadowstack.com/screens/task-board/): a card moves at once and the toast offers Undo.
- [Bank reconciliation](https://meadowstack.com/screens/bank-reconciliation/): pairing a payment applies at once, with Undo.
- [Document inbox](https://meadowstack.com/screens/document-inbox/): a filtered list with its no-results state.
- The kit's [AsyncState](https://meadowstack.com/components/async-state/) and [DataTable](https://meadowstack.com/components/data-table/), the [list](https://meadowstack.com/patterns/list/) that shows all four states, and the [approval flow](https://meadowstack.com/patterns/approval-flow/), whose moves are the optimistic changes above.

## Example apps that draw their states through AsyncState

*Which example apps and modules render the kit's AsyncState, computed from the demo's code when the site was built.*

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

## The check that fails a page without states

*Part of npm run check: a screen that loads data with useResource() and never renders AsyncState stops the check, the blank screen when the api fails caught before anyone sees it.*

From `scripts/check-states.mjs` in the Meadowstack repository:

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

## Related

- [AsyncState: every data view has four states](https://meadowstack.com/components/async-state/) (Components)
- [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)
