Commit dc607e45 authored by Tim Neutkens's avatar Tim Neutkens Committed by Arunoda Susiripala

Add docs for next/error (#2513)

parent 86c28377
...@@ -777,6 +777,37 @@ export default class Error extends React.Component { ...@@ -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 <Error statusCode={this.props.statusCode} />
}
return (
<div>Next stars: {this.props.stars}</div>
)
}
}
```
> If you have created a custom error page you have to import your own `_error` component instead of `next/error`
### Custom configuration ### 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`). 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`).
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment