Sub topic 1
Every screen has more than one state
A data-driven screen is not one fixed picture. It changes as data is requested, received, updated, or rejected. A project list, for example, can show a loading state, a list of projects, an empty state, or an error state.
At the intermediate level, assume you already know basic layout and component terms, have used asynchronous data fetching, and can read simple HTML and TypeScript. This chapter focuses on the working model for designing the screen states before you design the visual details.
Prerequisites
You should be familiar with:
- Layout, components, and interface copy.
- Asynchronous requests in web or mobile applications.
- Basic TypeScript and HTML reading.
Model the screen as states
Start by listing the meaningful states instead of designing only the successful case. A useful minimum model is:
| State | What it means | Typical user need |
|---|---|---|
| Loading | The app is fetching or preparing data | Know that work is happening |
| Success with data | The request succeeded and items exist | View or use the content |
| Success without data | The request succeeded but there are no items | Understand why it is empty and what to do |
| Error | The request or action failed | Understand the problem and recover |
These are product states, not merely visual styles. A spinner and a skeleton may both represent loading, but they communicate different expectations. Likewise, an empty list caused by a new account needs different content from an empty search result.
Do not combine states just because they look similar. “No projects exist” and “projects could not be loaded” may both display no rows, but they require different actions. The first may offer “Create project.” The second should offer “Try again.”
State transitions are part of the design
A screen moves between states over time. The initial request might follow this path:
A transition can also happen after the screen is visible. If someone creates the first project, the empty state should transition to the populated state. If a refresh fails while old data is available, replacing the list with a blank error screen may be worse than keeping the old list and showing a smaller refresh error.
Design each transition deliberately:
- What content remains visible?
- What changes immediately?
- Where does keyboard focus go?
- Can the user retry or undo the action?
- Does the system preserve data that is still valid?
Distinguish data state from presentation state
A data state describes what is true about the request and its result. A presentation state describes how the interface communicates that fact.
For example, loading data might use:
- A centered spinner for a short, uncertain wait.
- Skeleton rows when the layout is known and the wait may be longer.
- A progress bar when the system can measure meaningful progress.
- An optimistic update when the result is likely and showing it immediately helps the user.
These choices do not change the underlying state. They change how the wait feels and what the user can do during it.
Avoid showing a loading indicator for every tiny request. A spinner that appears for 50 milliseconds can flash and make the interface feel slower. Conversely, leaving the screen unchanged during a long request makes the interface appear stuck. The timing rule belongs to the component and request, not to a universal visual preference.
Prevent impossible combinations
Represent states so that invalid combinations cannot appear. A discriminated union is a TypeScript type whose status field identifies which other fields are available. It prevents code from treating an error as if it also had successful data.
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(", ");
}
}Here, an empty state is a successful result with an empty array. That distinction matters because the correct response is usually to guide the user, not to report a failure.
In a real screen, you may need additional states such as refreshing, saving, permission denied, or partially loaded. Add them when they change the available actions or the message. Do not add states only to mirror every internal implementation detail.
Review the state inventory
Before implementation, create a state inventory for the screen. Include the trigger, visible content, available actions, and recovery path. Then test each state with slow responses, failures, empty data, and repeated actions.
Exercise
A search screen receives an empty result after a successful request. Should it use the error state? What should it show instead?
Show answer
No. It should use a successful empty state. Explain that no matching items were found and provide a useful next action, such as changing the search terms or clearing the filter.