Commit a0341ea1 authored by Azim Atefi's avatar Azim Atefi Committed by Tim Neutkens

Convert Readme Custom Error Pages To Functional Component (#8513)

* Convert Readme Custom Error Pages To Functional Component

* Update packages/next/README.md
Co-Authored-By: 's avatarTim Neutkens <tim@timneutkens.nl>

* Run readme through prettier
parent 3e81acee
...@@ -17,7 +17,8 @@ ...@@ -17,7 +17,8 @@
"test": "yarn run testall || yarn run test-take2", "test": "yarn run testall || yarn run test-take2",
"lint": "lerna run typescript && standard && standard --parser typescript-eslint-parser --plugin typescript \"packages/**/*.ts\"", "lint": "lerna run typescript && standard && standard --parser typescript-eslint-parser --plugin typescript \"packages/**/*.ts\"",
"lint-fix": "standard --fix && standard --fix --parser typescript-eslint-parser --plugin typescript \"packages/**/*.ts\"", "lint-fix": "standard --fix && standard --fix --parser typescript-eslint-parser --plugin typescript \"packages/**/*.ts\"",
"prettier": "prettier --write \"**/*.{js,jsx,json,ts,tsx,md,mdx,css,html,yml,yaml,scss,sass}\" && yarn lint-fix", "prettier": "prettier --write",
"prettier-fix": "prettier --write \"**/*.{js,jsx,json,ts,tsx,md,mdx,css,html,yml,yaml,scss,sass}\" && yarn lint-fix",
"types": "lerna run types --stream", "types": "lerna run types --stream",
"typescript": "lerna run typescript", "typescript": "lerna run typescript",
"prepublish": "lerna run prepublish", "prepublish": "lerna run prepublish",
...@@ -40,6 +41,10 @@ ...@@ -40,6 +41,10 @@
"*.ts": [ "*.ts": [
"prettier --write", "prettier --write",
"git add" "git add"
],
"*.md": [
"prettier --write",
"git add"
] ]
}, },
"standard": { "standard": {
......
...@@ -596,7 +596,7 @@ const MyButton = React.forwardRef(({ onClick, href }, ref) => ( ...@@ -596,7 +596,7 @@ const MyButton = React.forwardRef(({ onClick, href }, ref) => (
export default () => ( export default () => (
<> <>
<Link href='/another'> <Link href="/another">
<MyButton /> <MyButton />
</Link> </Link>
</> </>
...@@ -1674,21 +1674,19 @@ export default MyDocument ...@@ -1674,21 +1674,19 @@ export default MyDocument
```jsx ```jsx
import React from 'react' import React from 'react'
class Error extends React.Component { function Error({ statusCode }) {
static getInitialProps({ res, err }) { return (
const statusCode = res ? res.statusCode : err ? err.statusCode : null <p>
return { statusCode } {statusCode
} ? `An error ${statusCode} occurred on server`
: 'An error occurred on client'}
</p>
)
}
render() { Error.getInitialProps = ({ res, err }) => {
return ( const statusCode = res ? res.statusCode : err ? err.statusCode : null
<p> return { statusCode }
{this.props.statusCode
? `An error ${this.props.statusCode} occurred on server`
: 'An error occurred on client'}
</p>
)
}
} }
export default Error export default Error
...@@ -1703,22 +1701,20 @@ import React from 'react' ...@@ -1703,22 +1701,20 @@ import React from 'react'
import Error from 'next/error' import Error from 'next/error'
import fetch from 'isomorphic-unfetch' import fetch from 'isomorphic-unfetch'
class Page extends React.Component { const Page = ({ errorCode, stars }) => {
static async getInitialProps() { if (errorCode) {
const res = await fetch('https://api.github.com/repos/zeit/next.js') return <Error statusCode={errorCode} />
const errorCode = res.statusCode > 200 ? res.statusCode : false
const json = await res.json()
return { errorCode, stars: json.stargazers_count }
} }
render() { return <div>Next stars: {stars}</div>
if (this.props.errorCode) { }
return <Error statusCode={this.props.errorCode} />
}
return <div>Next stars: {this.props.stars}</div> Page.getInitialProps = async () => {
} const res = await fetch('https://api.github.com/repos/zeit/next.js')
const errorCode = res.statusCode > 200 ? res.statusCode : false
const json = await res.json()
return { errorCode, stars: json.stargazers_count }
} }
export default Page export default Page
...@@ -2191,6 +2187,7 @@ Note: `NODE_ENV` is properly configured by the `next` subcommands, if absent, to ...@@ -2191,6 +2187,7 @@ Note: `NODE_ENV` is properly configured by the `next` subcommands, if absent, to
Note: we recommend putting `.next`, or your [custom dist folder](https://github.com/zeit/next.js#custom-configuration), in `.gitignore` or `.npmignore`. Otherwise, use `files` or `now.files` to opt-into a whitelist of files you want to deploy, excluding `.next` or your custom dist folder. Note: we recommend putting `.next`, or your [custom dist folder](https://github.com/zeit/next.js#custom-configuration), in `.gitignore` or `.npmignore`. Otherwise, use `files` or `now.files` to opt-into a whitelist of files you want to deploy, excluding `.next` or your custom dist folder.
### Compression ### Compression
Next.js provides [gzip](https://tools.ietf.org/html/rfc6713#section-3) compression to compress rendered content and static files. Compression only works with the `server` target. In general you will want to enable compression on a HTTP proxy like [nginx](https://www.nginx.com/), to offload load from the `Node.js` process. Next.js provides [gzip](https://tools.ietf.org/html/rfc6713#section-3) compression to compress rendered content and static files. Compression only works with the `server` target. In general you will want to enable compression on a HTTP proxy like [nginx](https://www.nginx.com/), to offload load from the `Node.js` process.
To disable **compression** in Next.js, set `compress` to `false` in `next.config.js`: To disable **compression** in Next.js, set `compress` to `false` in `next.config.js`:
......
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