Chapter 11 of 21
Continue learning Next.js step by step.
Loading & Error Handling
Learn how loading and error states work in Next.js.
Theory
Next.js provides special files such as loading.tsx and error.tsx.
loading.tsx can display a loading UI while content is being loaded.
error.tsx can provide an error UI when a route encounters an error.
Example
export default function Loading() {
return <p>Loading...</p>;
}Output
A loading message is displayed while the route content loads.
Practice
Create loading and error UI for a route.
Interview Questions
1
What is loading.tsx?
2
What is error.tsx?
3
Why are loading states important?
Quick Quiz
Which option best describes this chapter?
A.loading.tsx
B.wait.tsx
C.load.js
D.pending.tsx