Next.js · Junior · Question 12 of 75
Why must error.tsx be a client component?
- ✓Correct answer: It's a React error boundary, which only works on the client
- 2Server components can't render error text and stack traces
- 3The requirement applies only in development mode
Explanation
error.tsx wraps the segment in an error boundary - a client-side mechanism. The component receives error and a retry() function that reloads and re-renders the segment (there's also reset() - re-render without refetching data). Errors in the root layout are caught by global-error.tsx.