From dc607e452b35e68f46433d92e5ead621ce049855 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Sun, 9 Jul 2017 06:54:27 +0200 Subject: [PATCH] Add docs for next/error (#2513) --- readme.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/readme.md b/readme.md index 808bea2a..1ceb40c8 100644 --- a/readme.md +++ b/readme.md @@ -777,6 +777,37 @@ export default class Error extends React.Component { } ``` +### Reusing the build in error page + +If you want to render the build in error page you can by using `next/error`: + +```jsx +import React from 'react' +import Error from 'next/error' +import fetch from 'isomorphic-fetch' + +export default class Page extends React.Component { + static async getInitialProps () { + const res = await fetch('https://api.github.com/repos/zeit/next.js') + const statusCode = res.statusCode > 200 ? res.statusCode : false + const json = await res.json() + return { statusCode, stars: json.stargazers_count } + } + + render () { + if(this.props.statusCode) { + return + } + + return ( +
Next stars: {this.props.stars}
+ ) + } +} +``` + +> If you have created a custom error page you have to import your own `_error` component instead of `next/error` + ### Custom configuration For custom advanced behavior of Next.js, you can create a `next.config.js` in the root of your project directory (next to `pages/` and `package.json`).