Error.js
error.js handles runtime failures inside routes.
Definition
error.js is a route-level error boundary.
Why we use it
- Prevents app crash
- Graceful error recovery
When to use
Whenever routes fetch critical data.
"use client";
export default function Error({ error, reset }) {
return <button onClick={reset}>Retry</button>;
}Real-World Example
Payment failure screen with retry option.
Interview Tip
error.js isolates route failures without crashing the app.