Complete the code to define a basic error boundary component in Next.js using error.tsx.
export default function Error({ error }: { error: Error }) {
return <div>[1]</div>;
}The error component should return a user-friendly message. Returning An error occurred inside a div shows this message.
Complete the code to display the error message inside the error component.
export default function Error({ error }: { error: Error }) {
return <div>Error: [1]</div>;
}The message property of the error object holds the error text. Use error.message to show it.
Fix the error in the code to properly type the error prop in error.tsx.
export default function Error({ error }: [1]) {
return <div>{error.message}</div>;
}The error prop should be typed as Error to access message safely.
Fill both blanks to create a custom error component that logs the error and shows a message.
export default function Error({ error }: { error: Error }) {
[1](error);
return <div>[2]</div>;
}Use console.error to log errors clearly. Show a friendly message like An unexpected error happened to users.
Fill all three blanks to create an error component that shows the error name, message, and a retry button.
export default function Error({ error, reset }: { error: Error; reset: () => void }) {
return (
<main>
<h1>[1]</h1>
<p>[2]</p>
<button onClick=[3] aria-label="Retry loading page">Try again</button>
</main>
);
}Show the error's name in the heading, the message in a paragraph, and use the reset function for the retry button's click handler.