Next.js: Document next/error

Created on 14 Feb 2017  路  7Comments  路  Source: vercel/next.js

I don't think it's documented anywhere?

Also (unrelated to title, sorry), I guess it doesn't support any kind of message localization.

good first issue

All 7 comments

Yeah! Let's add it.

Isn't next/error just the default error page exported by pages/_error.js? It can be overwritten with a custom _error.js and is documented in README.md.

Or am I missing something :confused:? Maybe the fact that we can import and render it from any page is what you mean? :bulb:

Anyways I'll open a PR for #1069 and other documentation improvements, soon. Let me know and I'll add it to the list.

Yay, thanks! It's on the list. 馃棐

Thank you very much @nikvm 馃憤

@nikvm added the in progress label.

Something like this should suffice.

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>
    )
  }
}
Was this page helpful?
0 / 5 - 0 ratings