Sub topic 2
Writing and Laying Out an Empty State
This chapter assumes you know basic UI copy and layout, can read HTML, and can read TypeScript. It also assumes you have seen how an app fetches data asynchronously. Errors come later in the chapter, so the same copy rules carry over to them.
Why a screen is empty
An empty state is the screen you show when a list or view has no items to display. The cause decides the message. A new user has not created anything yet. A search matched nothing. Content was deleted. Each cause needs different words and a different next step.
Writing the message
Use three parts: a short heading that says what is missing, one sentence that explains why it matters, and one action the user can take. Keep the action specific. "Create project" tells the user more than "Get started."
type EmptyCause = "first-use" | "no-results" | "removed";
interface EmptyStateCopy {
heading: string;
body: string;
actionLabel?: string;
}
function emptyStateFor(cause: EmptyCause): EmptyStateCopy {
switch (cause) {
case "first-use":
return {
heading: "No projects yet",
body: "Projects hold your files and tasks.",
actionLabel: "Create project",
};
case "no-results":
return {
heading: "No matches",
body: "Try a different search term or clear your filters.",
actionLabel: "Clear filters",
};
case "removed":
return {
heading: "Nothing here anymore",
body: "The items you were viewing were deleted.",
};
}
}
console.log(emptyStateFor("first-use").heading);Laying out the empty state
Place the message where the list would appear, centered in the content area. Show the primary action as a button directly below the text. Do not show a blank grid with a faint hint in the corner.
Kinds of errors users meet
Errors fall into a few groups. Each group calls for a different message.
| Error type | Example | What the user can do |
|---|---|---|
| Network | Connection dropped during a save | Retry when back online |
| Validation | Name field is empty | Fix the input |
| Permission | Account lacks access to a folder | Ask an admin or switch accounts |
| Server | Service returned a 500 response | Retry later or contact support |
Writing error messages that help
A good error message says what happened, why if it is known, and what to do next. Avoid codes and jargon in the main text. Keep the code in a secondary line for support staff.
Exercise
Exercise
A search returns no results because the user typed a misspelled word. Which empty-state cause applies, and what action should the screen offer?
Show answer
The cause is "no-results". The screen should say no matches were found and offer a clear action, such as "Clear filters" or a suggestion to check the spelling and search again.