rsnext/examples/data-fetch/README.md

52 lines
1.3 KiB
Markdown
Raw Normal View History

2017-01-10 20:32:32 +01:00
# Data fetch example
## Deploy your own
Deploy the example using [ZEIT Now](https://zeit.co/now):
[![Deploy with ZEIT Now](https://zeit.co/button)](https://zeit.co/new/project?template=https://github.com/zeit/next.js/tree/canary/examples/data-fetch)
## How to use
### Using `create-next-app`
Execute [`create-next-app`](https://github.com/zeit/next.js/tree/canary/packages/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example:
```bash
npx create-next-app --example data-fetch data-fetch-app
# or
yarn create next-app --example data-fetch data-fetch-app
```
### Download manually
Download the example:
```bash
curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/data-fetch
cd data-fetch
```
Install it and run:
```bash
npm install
npm run dev
# or
yarn
yarn dev
```
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)):
```bash
now
```
## The idea behind the example
Next.js was conceived to make it easy to create universal apps. That's why fetching data
2018-01-03 14:06:45 +01:00
on the server and the client when necessary is so easy with Next.
2018-01-03 14:06:45 +01:00
Using `getInitialProps` fetches data on the server for SSR and then on the client when the component is re-mounted (not on the first paint).