Sub topic 1
Every screen has more than one state
Prerequisites
This chapter assumes you can:
- Use basic UI design vocabulary: layout, components, and copy (the words on the screen).
- Describe how a web or mobile app fetches data asynchronously. The request is sent, the interface keeps running, and a response arrives later or fails.
- Read short HTML and TypeScript examples.
You do not need to have built a production app. The later chapters in this tutorial go deeper on each state introduced here.
The screen you drew is only one of its states
Most design mockups show a screen full of realistic data: a list of ten projects, a profile photo, a chart with a clear trend. That mockup is one state of the screen, the one where everything worked and the user has plenty of data. A real screen that depends on data or on a user action passes through several other states, and users see them often.
- Loading: the data has been requested but has not arrived.
- Empty: the request worked, but there is nothing to show.
- Error: the request failed, or the user's action could not be completed.
- Content: the request worked and there is data to show. This is the state in the mockup.
A screen state is a distinct condition of the screen. In each one, the user sees something different and can do something different. Treating states as a deliberate design object means you decide what each one shows. If you skip that decision, the framework, the browser, or a developer in a hurry will decide for you. The usual result is a blank white area, a spinner that never stops, or a raw message like TypeError: undefined is not iterable.
Why the extra states matter
Designers sometimes call these "edge cases". Three facts show why that label is wrong.
- Every user starts in the loading state. Nobody sees data before the first response arrives. On a slow connection, loading may be the state they see longest.
- Every new user starts in the empty state. A new account has no projects, messages, or orders. Your onboarding experience is the empty state.
- Every network fails sometimes. Mobile connections drop, servers return errors, and sessions expire. A product used for long enough will meet every error you have not designed for.
The content state is the one a returning, well-connected user sees after they have built up data. Often that is the minority of real visits to a screen, and the first visit is the one that decides whether a person keeps using the product.
The core states and what each must answer
Each state should answer a question the user is silently asking. The table shows the four core states and the question each one answers.
| State | User's question | What the screen must do |
|---|---|---|
| Loading | Is something happening? | Show that work is in progress and, where possible, the shape of what is coming. |
| Empty | Is this broken, or is there just nothing here? | Explain why it is empty and offer a next step. |
| Error | What went wrong, and what can I do? | Say what happened in plain words and offer a way forward. |
| Content | What do I do with this? | Present the data and the actions available on it. |
A screen that cannot answer its state's question leaves the user guessing. A blank list is the clearest case. It could mean "still loading", "you have no items", or "the request failed", and the user cannot tell which. They may reload, give up, or file a support ticket. Each of those costs you something.
How states relate to each other
States are not a flat list. The screen moves between them in response to events: the screen opening, a response arriving, a failure, or a tap on "Try again". The diagram shows the basic flow for a screen that loads a list.
Three things in this diagram are easy to miss.
First, empty is a successful outcome. The request worked, and the answer was "nothing". Treating it as an error, for example by showing a red warning for a new user, tells people they did something wrong when they did not.
Second, there is an exit from every state. Error leads back to Loading through a retry. Empty leads to Content through a creation action. A state with no way out is a dead end, and users in a dead end leave.
Third, Refreshing is not the same as Loading. Once the screen has data, a later reload should usually keep the old data visible instead of replacing it with a blank loading view. This chapter names the difference. The chapters on loading patterns and error recovery cover how to design it.
Variations inside each state
The four core states are a starting point. Real screens have variants, and each variant may need its own design.
- First load and reload. First load has nothing to show. A reload has stale data you can keep on screen.
- Different kinds of empty. A new user with no data, a search with no matches, and a filter that hides everything are three different situations. They need different messages and different actions. "Create your first project" is wrong for a search that found nothing.
- Different kinds of error. A lost connection, an expired session, a missing permission, and a server failure have different causes and different fixes.
- Partial states. One section of a dashboard fails while the rest loads. The screen is in several states at once, one per region.
- Slow states. A request that takes 30 seconds is still "loading", but the user needs more reassurance than they do at 300 milliseconds.
You do not have to design every combination on day one. You do have to know which ones can happen on your screen, and decide on purpose which to treat separately and which to treat the same.
A screen is often a set of states
A common mistake is assigning one state to a whole page. A project page may have a header (loaded from one request), a task list (another), and an activity feed (a third). Each can be loading, empty, failed, or showing content on its own. If the whole page waits for the slowest request, one failing feed blocks everything.
A better rule is to give each independently loaded region its own state, and to show a page-level state only when nothing on the page can work. A practical way to find your regions is to list every request the screen makes and give each its own row in a table of states.
Modeling states so impossible ones cannot happen
Designers and developers often share a vocabulary of states by writing them down. In code, the common beginner approach is a set of independent flags.
// Fragile: three independent fields allow contradictory combinations.
interface ProjectsScreenFlags {
isLoading: boolean;
error: string | null;
projects: string[] | null;
}These three fields allow eight combinations, and many contradict each other. isLoading: true with an error set, or projects set at the same time as an error, has no meaning on screen. Code that reads these flags needs a chain of if statements, and the order of those checks silently decides which contradiction wins. That is where "spinner that never goes away" bugs come from.
A discriminated union is a type whose variants each carry a tag, here status, so that exactly one variant is active at a time. It fixes the problem by making the states mutually exclusive.
type AsyncState<T> =
| { status: "loading" }
| { status: "error"; message: string; retryable: boolean }
| { status: "success"; data: T };
function renderList(state: AsyncState<string[]>): string {
switch (state.status) {
case "loading":
return "Loading projects…";
case "error":
return state.retryable
? `${state.message} Try again.`
: state.message;
case "success":
return state.data.length === 0
? "No projects yet. Create your first project."
: state.data.join(", ");
}
}
console.log(renderList({ status: "loading" }));
console.log(renderList({ status: "success", data: [] }));
console.log(
renderList({ status: "error", message: "Couldn't load projects.", retryable: true })
);The type tells you three things about the design:
- Only one of loading, error, or success can be active, so the screen cannot show a spinner and an error together.
- An error carries a
messageand aretryableflag, so the screen always has something to say and knows whether to offer a retry button. - Empty is not a fourth status. It is a successful response whose
datais an empty array, and thesuccessbranch handles it explicitly. That matches the diagram: the request worked and the answer was "nothing".
The TypeScript compiler also helps when you add a state later. With strict enabled, a function with an unhandled variant fails to compile with an error that not every code path returns a value. The compiler then points to every screen that needs a decision about the new state.
Common mistakes
These are the errors this chapter's model is meant to prevent.
- Designing only the content state. The mockup is complete, but nobody drew loading, empty, or error.
- Showing a blank area while loading. The user cannot tell whether the screen is broken.
- Showing the same message for every failure. "Something went wrong" does not tell a person whether to retry, sign in again, or contact an administrator.
- Treating empty as an error. A new user gets a red warning for doing nothing wrong.
- Letting one failed request take down the whole page. Independent regions should fail independently.
- Replacing good data with a spinner on every refresh. The page flashes and the user loses their place.
- Dead ends. A state offers no action: no retry, no create button, no way back.
A working checklist
Use this list at the start of any screen design. It takes a few minutes, and it prevents most rework later.
- List every request or user action that changes what the screen shows.
- For each region, write down which of loading, empty, error, and content can occur.
- For each empty state, name the cause: new user, no search results, or cleared by a filter.
- For each error, name the cause and whether the user can fix it by retrying.
- For each state, write the one action the user should take next.
- Check that every state has a way out.
Exercise
A settings page loads the user's profile card and a list of connected devices from two separate requests. The devices request fails, and the profile request succeeds. Name the state of each region, and say why a single page-level error would be a poor design here.
Show answer
The profile card is in the content state, and the devices list is in the error state. A single page-level error would hide a working profile card and block the user from tasks that do not depend on the devices list. It would also give them no information about what failed. Each region should have its own state, with a retry action on the devices list only.
Exercise
Why is this type risky for a screen state: { isLoading: boolean; error: string | null; items: string[] | null }? Give one contradictory combination it allows, and name the type structure that prevents it.
Show answer
The three fields are independent, so the type allows eight combinations, and several contradict each other. For example, isLoading: true with error: "Network error" and a non-null items array would mean the screen is loading, failed, and showing content at once. A discriminated union with a status tag (loading, error, success) allows only one active variant, so contradictory combinations cannot be built.