Loading / Empty / Error
Three UI states as a reusable pattern for list fetches.
Every list screen needs at least: loading, empty (success but no rows), and error. Pick a userId that has posts (1–10) or invent a filter that yields none client-side.
State: idle
Important JavaScript
setState("loading");
try {
const rows = await loadRows();
if (rows.length === 0) {
setState("empty");
} else {
setState("data");
render(rows);
}
} catch (error) {
setState("error");
showError(error.message);
}