1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Use jsonPageRes instead of xhr (#1424)

This commit is contained in:
Tim Neutkens 2017-03-15 03:37:29 +01:00 committed by Arunoda Susiripala
parent d92ab55d22
commit 228bbbef74
4 changed files with 7 additions and 7 deletions

View file

@ -42,7 +42,7 @@ declare module "next/document" {
declare export var Main: Class<React$Component<void, any, any>>;
declare export var NextScript: Class<React$Component<void, any, any>>;
declare export default Class<React$Component<void, any, any>> & {
getInitialProps: (ctx: {pathname: string, query: any, req?: any, res?: any, xhr?: any, err?: any}) => Promise<any>;
getInitialProps: (ctx: {pathname: string, query: any, req?: any, res?: any, jsonPageRes?: any, err?: any}) => Promise<any>;
renderPage(cb: Function): void;
};
}

View file

@ -3,8 +3,8 @@ import HTTPStatus from 'http-status'
import Head from './head'
export default class Error extends React.Component {
static getInitialProps ({ res, xhr }) {
const statusCode = res ? res.statusCode : (xhr ? xhr.status : null)
static getInitialProps ({ res, jsonPageRes }) {
const statusCode = res ? res.statusCode : (jsonPageRes ? jsonPageRes.status : null)
return { statusCode }
}

View file

@ -341,7 +341,7 @@ export default class Router {
const res = await promise
// We need to clone this to prevent reading the body twice
// Becuase it's possible only once to read res.json() or a similar method.
// Because it's possible only once to read res.json() or a similar method.
return res.clone()
}

View file

@ -223,7 +223,7 @@ _Note: `getInitialProps` can **not** be used in children components. Only in `pa
- `query` - query string section of URL parsed as an object
- `req` - HTTP request object (server only)
- `res` - HTTP response object (server only)
- `xhr` - XMLHttpRequest object (client only)
- `jsonPageRes` - [Fetch Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) object (client only)
- `err` - Error object if any error is encountered during the rendering
### Routing
@ -602,8 +602,8 @@ The `ctx` object is equivalent to the one received in all [`getInitialProps`](#f
```jsx
import React from 'react'
export default class Error extends React.Component {
static getInitialProps ({ res, xhr }) {
const statusCode = res ? res.statusCode : (xhr ? xhr.status : null)
static getInitialProps ({ res, jsonPageRes }) {
const statusCode = res ? res.statusCode : (jsonPageRes ? jsonPageRes.status : null)
return { statusCode }
}