Complete the code to import the React library correctly.
import [1] from 'react';
In Next.js and React, you import the default React export as React to use JSX and React features.
Complete the code to define the error component as a React functional component.
export default function GlobalError({ error }: { error: Error }) {
return (
<div role="alert">
<h1>[1]</h1>
<p>{error.message}</p>
</div>
);
}The heading text must be a string inside quotes in JSX. Double quotes are standard for JSX strings.
Fix the error in the code to correctly display the error stack trace inside a <pre> tag.
<pre>[1]</pre>To display JavaScript variables inside JSX, wrap them in curly braces. error.stack shows the stack trace.
Fill both blanks to add a button that reloads the page when clicked.
<button onClick=[1]>[2]</button>
The onClick handler needs a function, so use an arrow function. The button text is a string without quotes in JSX.
Fill all three blanks to create a complete GlobalError component with error message, stack, and reload button.
export default function GlobalError({ error }: { error: Error }) {
return (
<main role="alert" aria-live="assertive">
<h1>[1]</h1>
<p>{error.message}</p>
<pre>[2]</pre>
<button onClick=[3]>Reload</button>
</main>
);
}The heading is a string in quotes, the stack trace is embedded with curly braces, and the reload button uses an arrow function for onClick.