loading.tsx provides instant fallback UI while a route segment’s async Server Component work completes. Next.js wraps the segment in a Suspense boundary automatically.
File placement
app/dashboard/
loading.tsx # skeleton for dashboard segment
page.tsx # async data fetch
export default function Loading() {
return <p>Loading dashboard…</p>;
}
Streaming benefit
Slow data no longer blocks the entire page shell—layouts and fast sections stream first; heavy segments resolve later.
Client-side loading states
Inside Client Components, use local useState for button spinners or SWR loading flags—loading.tsx covers the server segment boundary.
Self-check
- What React primitive does
loading.tsxmap to? - Why place loading UI in the same folder as the slow page?
Challenge
Loading simulation
- Click Load data and watch the loading flag.
- Adjust the delay constant and re-run.
Done when: UI shows loading then content after the simulated fetch.