Loading & Error UI
Implement loading states with `loading.js` and gracefully handle errors using `error.js` boundaries in your application.
Why Loading States Matter
When your Next.js application fetches data, it can take some time. Without any visual feedback, users might think the app is frozen or broken.
- Improve User Experience: Keep users informed.
- Reduce Frustration: Prevent perceived slowness.
- Indicate Progress: Show that something is happening in the background.
Introducing `loading.js`
Next.js App Router provides a special file convention, loading.js, to automatically create a loading UI for a route segment.
When data is being fetched for a page.js or layout.js file, Next.js automatically displays the UI defined in its nearest loading.js sibling or ancestor.