Skip to content

Patterns

Async states

Data comes from a server: it takes time, it can fail, and it can be empty. Without a decided answer every screen invents its own spinner, its own red box and its own blank table.

Reference build

Live, built only from system components. Switch the width: the build uses its own breakpoints.

Rules

  1. The region keeps its heading and actions in every state; only the content below them changes.
  2. Loading: one sentence in a live region (role=status) saying what loads. An action people triggered shows loading on its Button.
  3. Failure: InlineMessage tone danger with what failed and a Try again button right below it. Use Banner only when the whole page is affected.
  4. Nothing there: EmptyState with the reason and one action, never an empty table.
  5. Content: the table or list, with its caption.
  6. Never keep stale content next to an error without saying it is stale.

Layout and states

What every build of this pattern must hold to. The check runs the required states on the reference build.
Layout
Stack with gap-stack-relaxed: the region head (gap-stack), then one of the four states in the same place.
Small screens: reflow
Every state uses the full width of its region; the table scrolls inside its own region.
Required states
StateProves
loadingWhile data loads, a status message says what is loading.
failedA failure shows what went wrong and a Try again action.
emptyNo data shows EmptyState instead of an empty table.
loadedData shows the table with its caption.

Code

src/patterns/async-states/Example.tsx
"use client";

// Client component: it holds the demo state. Client components import from src/ds by path (CLAUDE.md).
import { useState } from "react";
import { Button } from "@/ds/Button/Button";
import { EmptyState } from "@/ds/EmptyState/EmptyState";
import { Heading } from "@/ds/Heading/Heading";
import { InlineMessage } from "@/ds/InlineMessage/InlineMessage";
import { Table } from "@/ds/Table/Table";

type State = "loading" | "failed" | "empty" | "loaded";

const demoStates: { value: State; label: string }[] = [
  { value: "loading", label: "Loading" },
  { value: "failed", label: "Failed" },
  { value: "empty", label: "Empty" },
  { value: "loaded", label: "Loaded" },
];

const requests = [
  { request: "Placeholder: request A", received: "2026-11-12", status: "New" },
  { request: "Placeholder: request B", received: "2026-11-10", status: "In review" },
  { request: "Placeholder: request C", received: "2026-11-04", status: "Answered" },
];

export function Example() {
  // The buttons only switch the demo; in a screen the state comes from the request.
  const [state, setState] = useState<State>("loading");
  return (
    <div className="flex flex-col gap-group">
      <div role="group" aria-label="Demo: state of the request" className="flex flex-wrap gap-inline">
        {demoStates.map(({ value, label }) => (
          <Button key={value} variant="secondary" size="sm" aria-pressed={state === value} onClick={() => setState(value)}>
            {label}
          </Button>
        ))}
      </div>
      <section aria-labelledby="async-requests" className="flex flex-col gap-stack-relaxed">
        <Heading as="h3" id="async-requests">
          Requests
        </Heading>
        {state === "loading" && (
          <p role="status" className="text-secondary">
            Loading requests …
          </p>
        )}
        {state === "failed" && (
          <div className="flex flex-col gap-stack">
            <InlineMessage tone="danger" title="Requests could not be loaded." announce>
              The server did not answer. Your data is safe.
            </InlineMessage>
            <div>
              <Button variant="secondary" onClick={() => setState("loading")}>
                Try again
              </Button>
            </div>
          </div>
        )}
        {state === "empty" && (
          <EmptyState title="No requests yet" action={<Button variant="secondary">Share the request form</Button>}>
            New requests appear here as soon as someone sends the form.
          </EmptyState>
        )}
        {state === "loaded" && (
          <Table
            caption="Requests, newest first"
            rowKey="request"
            columns={[
              { key: "request", header: "Request" },
              { key: "received", header: "Received" },
              { key: "status", header: "Status" },
            ]}
            rows={requests}
          />
        )}
      </section>
    </div>
  );
}

Built from

Seen in: CRM overview “Not enough data yet” (S3). Loading and failure were not yet decided anywhere; added before round 5, which uses them.