How should a page distinguish loading, empty, and failed data?
Quick answer
Represent the request with four mutually exclusive states: loading, success with items, success with no items, and error. Show a loading indicator while waiting, an empty-state message only after a successful response contains no items, the collection when items exist, and an error message if the request fails. Keeping these states separate prevents a network problem from being mistaken for an empty collection.
The question, the details, the next step.
A practical checklist
Set an explicit loading state before starting the request.
Set empty only after success with an empty collection.
Render the collection only after success with items.
Render an error state when the request fails; don’t substitute an empty state.
Check each state and the error-to-loading retry transition.
Decide whether existing data remains visible during a refresh.
A few more useful answers
Can I use the same message for an empty result and a failed request?
It is better to distinguish them. Empty means the request succeeded and found no items; error means the page could not determine the result.
Should an empty array be the initial value?
It can be stored internally, but don’t use it alone to decide that the empty state should appear. Track whether the request is loading, has succeeded, or has failed.
What if a refresh fails but the page already has items?
Choose deliberately whether to retain the existing list and show a refresh error, or replace it with a full error state. In either case, don’t describe the collection as empty unless a successful result was empty.
