Problem Statement
How does error.js work in the App Router?
Explanation
error.js automatically creates a React Error Boundary around route segments that catches JavaScript errors during rendering, in event handlers, or in nested components, displaying the error UI instead of breaking the entire application.
The error component receives error and reset props, where error contains error details and reset is a function to retry rendering the segment.
Error boundaries are nested like layouts, so errors bubble up to the nearest parent error boundary, and error.js must be a Client Component marked with 'use client' since it needs interactivity for the reset function.
Practice Sets
This question appears in the following practice sets: