Loading & error states
Exercise35 min
Loading & error states
Every data-driven screen has four truths: empty, loading, error, success. Users forgive slowness; they do not forgive a blank screen.
if (state.loading) return <Spinner label="Loading lessons…" />;
if (state.error) return <ErrorPanel message={state.error.message} onRetry={refetch} />;
if (!state.data?.length) return <EmptyState title="No lessons yet" />;
return <LessonList lessons={state.data} />;Treat the four states as part of the component's contract, not as polish. A component that only handles success is a component that lies.
Exercise
Take your fetch from the last lesson and render all four states, including a retry button on error that refetches.
Practice in the diagram lab
This lesson's practice belongs in the diagram editor — design the schema you just read about, grade it against the solution, and save it to your account.
Open the diagram lab