Unverified Commit f33ba2c5 authored by Luis Alvarez D's avatar Luis Alvarez D Committed by GitHub

[docs] Mention the new data fetching methods on missing places (#11620)

Co-authored-by: 's avatarTim Neutkens <timneutkens@me.com>
parent 969ffd6c
...@@ -54,25 +54,25 @@ If you want to render the built-in error page you can by importing the `Error` c ...@@ -54,25 +54,25 @@ If you want to render the built-in error page you can by importing the `Error` c
```jsx ```jsx
import Error from 'next/error' import Error from 'next/error'
import fetch from 'isomorphic-unfetch' import fetch from 'node-fetch'
const Page = ({ errorCode, stars }) => { export async function getServerSideProps() {
const res = await fetch('https://api.github.com/repos/zeit/next.js')
const errorCode = res.ok ? false : res.statusCode
const json = await res.json()
return {
props: { errorCode, stars: json.stargazers_count },
}
}
export default function Page({ errorCode, stars }) {
if (errorCode) { if (errorCode) {
return <Error statusCode={errorCode} /> return <Error statusCode={errorCode} />
} }
return <div>Next stars: {stars}</div> return <div>Next stars: {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
``` ```
The `Error` component also takes `title` as a property if you want to pass in a text message along with a `statusCode`. The `Error` component also takes `title` as a property if you want to pass in a text message along with a `statusCode`.
...@@ -133,6 +133,13 @@ export default class Page extends React.Component<Props> { ...@@ -133,6 +133,13 @@ export default class Page extends React.Component<Props> {
For more information on what to do next, we recommend the following sections: For more information on what to do next, we recommend the following sections:
<div class="card">
<a href="/docs/basic-features/data-fetching.md">
<b>Data Fetching:</b>
<small>Learn more about data fetching in Next.js.</small>
</a>
</div>
<div class="card"> <div class="card">
<a href="/docs/basic-features/pages.md"> <a href="/docs/basic-features/pages.md">
<b>Pages:</b> <b>Pages:</b>
...@@ -141,8 +148,8 @@ For more information on what to do next, we recommend the following sections: ...@@ -141,8 +148,8 @@ For more information on what to do next, we recommend the following sections:
</div> </div>
<div class="card"> <div class="card">
<a href="/docs/basic-features/data-fetching.md"> <a href="/docs/advanced-features/automatic-static-optimization.md">
<b>Data Fetching:</b> <b>Automatic Static Optimization:</b>
<small>Learn more about data fetching in Next.js.</small> <small>Learn about how Nextjs automatically optimizes your pages.</small>
</a> </a>
</div> </div>
...@@ -87,7 +87,7 @@ Router.push(url, as, options) ...@@ -87,7 +87,7 @@ Router.push(url, as, options)
- `url` - The URL to navigate to. This is usually the name of a `page` - `url` - The URL to navigate to. This is usually the name of a `page`
- `as` - Optional decorator for the URL that will be shown in the browser. Defaults to `url` - `as` - Optional decorator for the URL that will be shown in the browser. Defaults to `url`
- `options` - Optional object with the following configuration options: - `options` - Optional object with the following configuration options:
- [`shallow`](/docs/routing/shallow-routing.md): Update the path of the current page without rerunning `getInitialProps`. Defaults to `false` - [`shallow`](/docs/routing/shallow-routing.md): Update the path of the current page without rerunning `getServerSideProps` or `getInitialProps`. Defaults to `false`
> You don't need to use `Router` for external URLs, [window.location](https://developer.mozilla.org/en-US/docs/Web/API/Window/location) is better suited for those cases. > You don't need to use `Router` for external URLs, [window.location](https://developer.mozilla.org/en-US/docs/Web/API/Window/location) is better suited for those cases.
......
...@@ -46,7 +46,7 @@ description: Get to know more about Next.js with the frequently asked questions. ...@@ -46,7 +46,7 @@ description: Get to know more about Next.js with the frequently asked questions.
<details> <details>
<summary>How do I fetch data?</summary> <summary>How do I fetch data?</summary>
<p>It's up to you. You can use the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch">fetch API</a> inside your React components, or <a href="/docs/basic-features/data-fetching.md">Data fetching</a> for initial data population.</p> <p>It's up to you. You can use the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch">fetch API</a> or <a href="https://swr.now.sh/">SWR</a> inside your React components for remote data fetching; or use our <a href="/docs/basic-features/data-fetching.md">data fetching methods</a> for initial data population.</p>
</details> </details>
<details> <details>
......
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