How do I create an Error page in Next.js using Typescript?
I attempted the following:
interface ErrorProps {
statusCode: number;
}
function Error({ statusCode }: ErrorProps) {
return (
<p>
{statusCode
? `An error ${statusCode} occurred on the server`
: "An error occurred on the client"}
</p>
);
}
interface InitialProps {
res: NextApiResponse;
err: NextApiResponse;
}
Error.getInitialProps = ({ res, err }: InitialProps) => {
const statusCode = res ? res.statusCode : err ? err.statusCode : 404;
return { statusCode };
};
However, I'm uncertain if this is the correct approach.