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
5d70b2a0
Unverified
Commit
5d70b2a0
authored
May 08, 2020
by
Luis Alvarez D
Committed by
GitHub
May 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Examples] Update data-fetch example (#12617)
parent
7a025811
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
7 deletions
+7
-7
index.js
examples/data-fetch/pages/index.js
+3
-3
preact-stars.js
examples/data-fetch/pages/preact-stars.js
+4
-4
No files found.
examples/data-fetch/pages/index.js
View file @
5d70b2a0
import
React
from
'react'
import
Link
from
'next/link'
import
fetch
from
'node-fetch'
...
...
@@ -6,7 +5,7 @@ function Index({ stars }) {
return
(
<
div
>
<
p
>
Next
.
js
has
{
stars
}
⭐️
<
/p
>
<
Link
href
=
"/preact"
>
<
Link
href
=
"/preact
-stars
"
>
<
a
>
How
about
preact
?
<
/a
>
<
/Link
>
<
/div
>
...
...
@@ -15,7 +14,8 @@ function Index({ stars }) {
export
async
function
getStaticProps
()
{
const
res
=
await
fetch
(
'https://api.github.com/repos/zeit/next.js'
)
const
json
=
await
res
.
json
()
// better use it inside try .. catch
const
json
=
await
res
.
json
()
return
{
props
:
{
stars
:
json
.
stargazers_count
,
...
...
examples/data-fetch/pages/preact.js
→
examples/data-fetch/pages/preact
-stars
.js
View file @
5d70b2a0
import
React
from
'react'
import
Link
from
'next/link'
import
fetch
from
'node-fetch'
function
Preact
({
stars
})
{
function
Preact
Stars
({
stars
})
{
return
(
<
div
>
<
p
>
Preact
has
{
stars
}
⭐
<
/p
>
...
...
@@ -15,7 +14,8 @@ function Preact({ stars }) {
export
async
function
getStaticProps
()
{
const
res
=
await
fetch
(
'https://api.github.com/repos/developit/preact'
)
const
json
=
await
res
.
json
()
// better use it inside try .. catch
const
json
=
await
res
.
json
()
return
{
props
:
{
stars
:
json
.
stargazers_count
,
...
...
@@ -23,4 +23,4 @@ export async function getStaticProps() {
}
}
export
default
Preact
export
default
Preact
Stars
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