Projects

Fetch & Render

Fetch data from an API and render it beautifully. This project covers loading states, skeleton loaders, error handling, search with debounce, client-side pagination, and the infinite scroll pattern.

What You Will Build

1

Fetch with States

Idle → Loading → Success/Error state machine

2

Skeleton Loader

Shimmering placeholders while data loads

3

Search + Filter

Debounced search across multiple fields

4

Pagination & Infinite

Page-based and intersection observer scroll

Loading State Patterns

State Machine

Any fetched data

Define explicit states: IDLE, LOADING, SUCCESS, ERROR. Prevents impossible combinations like showing data AND an error simultaneously.

Skeleton Loader

Content-heavy UIs

CSS shimmer placeholders that match the final layout. Better UX than a spinner — user sees the layout shape immediately.

Optimistic Update

Like/save/delete actions

Show the result before the server responds. Roll back on error. Makes CRUD feel instant.

Stale-While-Revalidate

Lists, dashboards

Show cached data immediately, fetch fresh data in background, silently update when done.

Suspense / Deferred

Complex pages

Break page into independent sections. Each fetches independently — slow sections don't block fast ones.

Abort Controller

All fetch calls

Cancel in-flight requests when component unmounts or user navigates away. Prevents state updates on unmounted components.

Common Pitfalls

No loading state — content flashes in abruptly, users see empty containers
Show skeletons or spinners immediately. The DOM should reflect the LOADING state before any data arrives.
Searching on every keystroke — floods API with requests, freezes UI on large datasets
Debounce search: clearTimeout + setTimeout 150-300ms. Cancel previous request with AbortController.
Race condition: fast second response overwrites slow first response
Track a request ID or use AbortController. Ignore/cancel responses that are no longer the latest request.
Showing nothing on error — user doesn't know what happened or how to retry
Show a friendly error message with the problem description and a Retry button that re-triggers the fetch.

Build It Live

Code Editor

<input id="search" placeholder="Filter users…">
<p id="status">Loading…</p>
<ul id="users"></ul>

Preview

Fetch and Render — step by step

1 / 4
1

Fetching Data Asynchronously

Call fetch with a URL, await the Promise, then call .json() (another Promise) to parse the body. Always check response.ok before parsing — fetch only rejects on network failure, not on 4xx/5xx HTTP errors.

1 of 4
⚠️fetch Does Not Reject on HTTP Errors
A 404 or 500 response still resolves the Promise — only a network failure rejects it. Always check response.ok (true for 200-299) or inspect response.status before calling response.json, otherwise you may silently parse an error payload as if it were valid data.

🎯 Quick Check

What does response.ok check in a fetch response?

Next project

Drag & Drop