---
title: "Loading states"
description: "Wire a loader to real app state, from a wait to done or failed, a progress value, a pause, and an exit that fades the dots out."
url: "https://dotsengine.dev/docs/states"
markdown: "https://dotsengine.dev/docs/states.md"
updated: 2026-12-01
---

# Loading states

Wire a loader to real app state, from a wait to done or failed, a progress value, a pause, and an exit that fades the dots out.

> The other pages of this site, each with its Markdown copy, are listed in [llms.txt](https://dotsengine.dev/llms.txt).

A loader follows your app's state through its props. You never call a method on it. Change a prop, and the dots morph to the new state.

| App state               | Props                                        |
| ----------------------- | -------------------------------------------- |
| Working, length unknown | A loop, such as `pattern="spinner"`          |
| Working, with progress  | `pattern="progress"` and `value` from 0 to 1 |
| Done                    | `pattern="check"`                            |
| Failed                  | `pattern="cross"`                            |
| On hold                 | `state="paused"`                             |
| Gone                    | `active={false}`, then unmount               |

## From a wait to a result

Switch the pattern when the work ends. The dots morph from the loop to the result. `check` and `cross` play one time and hold the last frame.

```tsx
type Status = "pending" | "done" | "failed";

const PATTERN = { pending: "spinner", done: "check", failed: "cross" } as const;
const COLOR = {
  pending: undefined,
  done: "#16a34a",
  failed: "var(--color-destructive)",
} as const;

export function SaveStatus({ status }: { status: Status }) {
  return (
    <DotMatrix
      pattern={PATTERN[status]}
      color={COLOR[status]}
      lattice="circle"
      size={20}
      look={{ morph: "fly", grid: 7 }}
    />
  );
}
```

- A screen reader hears "Done" or "Something went wrong" once, when the pattern changes.
- Set `look.grid` when one loader switches patterns. Patterns can pick different grids, and a fixed grid keeps each dot in its place during the morph.
- Use your own theme tokens for the colors. shadcn themes have `--color-destructive` but no success color, so this example uses a plain green. `undefined` keeps the text color.

```dot-matrix
[
  { "name": "pending", "pattern": "spinner", "lattice": "circle", "grid": 7 },
  { "name": "done", "pattern": "check", "lattice": "circle", "grid": 7, "color": "success" },
  { "name": "failed", "pattern": "cross", "lattice": "circle", "grid": 7, "color": "destructive" }
]
```

## Show progress

`progress`, `progressRing` and `voice` read `value`. Pass a number from 0 to 1. Change it as often as you want: the dots blend to the new value.

```tsx
<DotMatrix
  pattern="progressRing"
  lattice="circle"
  value={total === 0 ? 0 : loaded / total}
  aria-label={`Uploading, ${Math.round((loaded / total) * 100)}%`}
/>
```

When the upload ends, switch to `check`. The ring morphs into the mark.

The canvas and WebGL renderers blend the two nearest steps of the value. The DOM and SVG renderers show the nearest step. So they suit a progress better than a sound level.

## Pause

`state="paused"` holds the current frame. `state="running"` goes on. Use it when work stops for a while, such as a queue that waits for the network.

```tsx
<DotMatrix pattern="equalizer" state={online ? "running" : "paused"} />
```

The loop also stops by itself when the loader is off screen or the tab is hidden. You do not need to pause it for that.

## Exit and enter

`active={false}` morphs every dot dark, in 560ms. Keep the loader mounted during that time, then remove it.

```tsx
export function Job({ busy }: { busy: boolean }) {
  const [shown, setShown] = useState(true);
  useEffect(() => {
    if (busy) {
      return;
    }
    // The exit morph takes 560ms: unmount after it.
    const timer = setTimeout(() => setShown(false), 560);
    return () => clearTimeout(timer);
  }, [busy]);
  return shown ? <DotMatrix pattern="orbit" active={busy} /> : null;
}
```

`enter` does the opposite. The loader starts dark and morphs in the first time it comes on screen.

```tsx
<DotMatrix pattern="radar" lattice="circle" enter />
```

## When a change does not morph

A morph needs a running loader on screen. In these cases the change shows at once:

- `look.morph` is `"none"`.
- The loader is paused, off screen, or in a hidden tab.
- The change is to `size`, `look.dot`, `look.glow`, `look.floor` or `renderer`. These mount a new layer.

[Motion](https://dotsengine.dev/docs/motion.md) lists the morph kinds and the speed.
