{"success":true,"name":"show-the-three-faces-of-every-fetch-loading-error-and-empty-","description":"Building a frontend screen or component that fetches data from an API","category":"ai-brimind","path":"ai-brimind/show-the-three-faces-of-every-fetch-loading-error-and-empty-/SKILL.md","file":"SKILL.md","content":"---\nname: show-the-three-faces-of-every-fetch-loading-error-and-empty-\ndescription: \"Building a frontend screen or component that fetches data from an API\"\n---\n\n# Show the Three Faces of Every Fetch: Loading, Error, and Empty Are Not Optional\n\n## When to use\nBuilding a frontend screen or component that fetches data from an API\n\n## Example request\nOrders page renders a list straight from the fetch → on a slow network the user stares at a blank page wondering if it is broken; a visible loading state was the missing piece. API returns 500 and the component shows nothing or crashes on undefined → the user cannot tell failure from emptiness; an error state with a retry is the honest answer. New user with zero orders sees a blank white area → 'You have no orders yet' plus a call-to-action turns confusion into guidance; empty is a real state, not an accident. Data arrives but the code reads response.data.items.length without checks → one missing field crashes the whole screen; the render must match the states the fetch can actually produce.\n\n## Instructions\nAct as a frontend developer who knows every fetch has at least four endings — loading, error, empty, and success — and that a screen handling only success is a screen that lies three times out of four. For every data-loading component you build, do this: (1) Before styling anything, list the states this fetch can produce: request in flight, request failed, request succeeded with zero items, request succeeded with data. If the data can also be partially missing (optional fields), note that too. (2) Represent the states honestly in your component's logic — whether via your data-fetching library's built-in flags (isLoading, isError — check what the project already uses before inventing your own booleans) or explicit state — so the render can branch on them. (3) Give each state a face the user understands: a skeleton or spinner for loading (so the app feels alive), a human message plus a retry action for errors (never a blank screen, never raw error text like 'AxiosError 500'), and for empty — the most forgotten one — a friendly explanation with a next step ('No projects yet. Create your first one'). (4) Guard the success render itself: read nested fields safely so one missing property does not crash the page; render what exists. (5) Test all faces cheaply before shipping: throttle the network to see loading, kill the backend or break the URL to see error, use a fresh account to see empty. Clicking through with your seeded dev data only ever shows you success. Only call the component done once you have SEEN all four states on screen with your own eyes and each one tells the user something true about what is happening.\n\n## Metadata\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #197\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}