Skip to content

commandFrontend

Add Loading States

Adds loading, empty and error states to a view that fetches data, using the spinners, skeletons and messages the app already has.

npx workspacetemplates add add-loading-states --tool claude-code

Writes 1 file to .claude/commands/

.claude/commands/add-loading-states.md14 lines · 1.2 KBFile
---
description: Adds loading, empty and error states to a view that fetches data, using the spinners, skeletons and messages the app already has.
argument-hint: "[view or component path]"
---

Add loading, empty and error states to the view: $ARGUMENTS

1. Read the view and trace where its data comes from (hook, loader, store, fetch call). Note what the code currently does while pending, on an empty result and on failure.
2. Search the codebase for existing patterns: skeleton or spinner components, empty-state illustrations, error banners, toast helpers. Reuse them; create a new component only if none exists.
3. Implement: a loading state that matches the final layout size to avoid jumps; an empty state with a short message and the next action; an error state with the reason in plain words and a retry button that calls the same fetch.
4. Mark loading regions with `aria-busy` and announce errors with `role="alert"`. Do not show a spinner for requests under about 300 ms if the app has a delay helper.
5. Add or update tests for the three states using the project's mocking approach.

Run the tests and type check. Report which states were missing, what was reused, and anything in the data layer you did not change.

What it does

Many screens handle only the success case, so users see a blank area while data loads or a frozen page when a request fails. This command finds the data flow in the view you name and covers the three missing states.

It reuses the existing skeletons, banners and copy style of the app, and it keeps retry behavior simple and visible.

Example

you › /add-loading-states src/views/Invoices.tsx

agent › Added: TableSkeleton while pending (existing component), EmptyState "No invoices yet. Create one" with a link, ErrorBanner with Retry wired to refetch().
Tests added for all three (Invoices.test.tsx). tsc and vitest pass. The export-to-CSV button still has no error state.

Questions

Will it invent new components?
Only when it cannot find an existing skeleton, banner or empty state. It searches first and says what it reused.
Does it change my API calls?
No. It reads the data flow and reports weaknesses it sees in the data layer, but edits only the view and its tests.
  • A11y Check

    CommandFrontend

    Free
  • Add Form Validation

    CommandFrontend

    Free
  • Check Responsive

    CommandFrontend

    Free
  • Convert to TypeScript

    Commandtypescript

    Free