[Examples] Update data-fetch example (#12617)
This commit is contained in:
parent
7a02581159
commit
5d70b2a06f
2 changed files with 7 additions and 7 deletions
|
@ -1,4 +1,3 @@
|
|||
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,
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import React from 'react'
|
||||
import Link from 'next/link'
|
||||
import fetch from 'node-fetch'
|
||||
|
||||
function Preact({ stars }) {
|
||||
function PreactStars({ 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 PreactStars
|
Loading…
Reference in a new issue