Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
9ff7339e
Unverified
Commit
9ff7339e
authored
Oct 10, 2019
by
Tim Neutkens
Committed by
GitHub
Oct 10, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add @zeit/fetch example (#9029)
parent
de670b38
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
114 additions
and
0 deletions
+114
-0
README.md
examples/with-zeit-fetch/README.md
+42
-0
browser.js
examples/with-zeit-fetch/fetch/browser.js
+3
-0
package.json
examples/with-zeit-fetch/fetch/package.json
+4
-0
server.js
examples/with-zeit-fetch/fetch/server.js
+3
-0
package.json
examples/with-zeit-fetch/package.json
+18
-0
index.js
examples/with-zeit-fetch/pages/index.js
+22
-0
preact.js
examples/with-zeit-fetch/pages/preact.js
+22
-0
No files found.
examples/with-zeit-fetch/README.md
0 → 100644
View file @
9ff7339e
# @zeit/fetch example
## How to use
### Using `create-next-app`
Execute
[
`create-next-app`
](
https://github.com/segmentio/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
with-zeit-fetch-app
# or
yarn create next-app
--example
with-zeit-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/with-zeit-fetch
cd
with-zeit-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
This example shows how to use
[
`@zeit/fetch`
](
https://npmjs.com/zeit/fetch
)
in a Next.js application.
examples/with-zeit-fetch/fetch/browser.js
0 → 100644
View file @
9ff7339e
import
fetch
from
'isomorphic-fetch'
export
default
fetch
examples/with-zeit-fetch/fetch/package.json
0 → 100644
View file @
9ff7339e
{
"browser"
:
"./browser.js"
,
"main"
:
"./server.js"
}
\ No newline at end of file
examples/with-zeit-fetch/fetch/server.js
0 → 100644
View file @
9ff7339e
import
zeitFetch
from
'@zeit/fetch'
export
default
zeitFetch
()
examples/with-zeit-fetch/package.json
0 → 100644
View file @
9ff7339e
{
"name"
:
"data-fetch"
,
"version"
:
"1.0.0"
,
"scripts"
:
{
"dev"
:
"next"
,
"build"
:
"next build"
,
"start"
:
"next start"
},
"dependencies"
:
{
"@zeit/fetch"
:
"5.1.1"
,
"next"
:
"latest"
,
"node-fetch"
:
"2.6.0"
,
"react"
:
"^16.8.4"
,
"react-dom"
:
"^16.8.4"
,
"unfetch"
:
"4.1.0"
},
"license"
:
"ISC"
}
examples/with-zeit-fetch/pages/index.js
0 → 100644
View file @
9ff7339e
import
React
from
'react'
import
Link
from
'next/link'
import
fetch
from
'../fetch'
function
Index
(
props
)
{
return
(
<
div
>
<
p
>
Next
.
js
has
{
props
.
stars
}
⭐️
<
/p
>
<
Link
href
=
'/preact'
>
<
a
>
How
about
preact
?
<
/a
>
<
/Link
>
<
/div
>
)
}
Index
.
getInitialProps
=
async
()
=>
{
const
res
=
await
fetch
(
'https://api.github.com/repos/zeit/next.js'
)
const
json
=
await
res
.
json
()
// better use it inside try .. catch
return
{
stars
:
json
.
stargazers_count
}
}
export
default
Index
examples/with-zeit-fetch/pages/preact.js
0 → 100644
View file @
9ff7339e
import
React
from
'react'
import
Link
from
'next/link'
import
fetch
from
'../fetch'
function
Preact
(
props
)
{
return
(
<
div
>
<
p
>
Preact
has
{
props
.
stars
}
⭐
<
/p
>
<
Link
href
=
'/'
>
<
a
>
I
bet
Next
.
js
has
more
stars
(?)
<
/a
>
<
/Link
>
<
/div
>
)
}
Preact
.
getInitialProps
=
async
()
=>
{
const
res
=
await
fetch
(
'https://api.github.com/repos/developit/preact'
)
const
json
=
await
res
.
json
()
// better use it inside try .. catch
return
{
stars
:
json
.
stargazers_count
}
}
export
default
Preact
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment