Last active
April 17, 2023 10:26
-
-
Save tiptopcoder/ee56b81e1d8e0a7e79b755b2d60b72fd to your computer and use it in GitHub Desktop.
Next.js Typescript error page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NextPageContext } from "next"; | |
const Error = ({ statusCode }) => { | |
return ( | |
<p> | |
{statusCode | |
? `An error ${statusCode} occurred on server` | |
: "An error occurred on client"} | |
</p> | |
); | |
}; | |
Error.getInitialProps = ({ res, err }: NextPageContext) => { | |
const statusCode = res ? res.statusCode : err ? err.statusCode : 404; | |
return { statusCode }; | |
}; | |
export default Error; |
NextPage
TypeScript type on the component seems to handle everything.
import { NextPage } from 'next';
const Error: NextPage = () => {......}
Error.getInitialProps = ({ res, err }) => {.....};
export default Error;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@tim1uphealth you mean like this?