[Examples] Update data-fetch example (#12617)

This commit is contained in:
Luis Alvarez D 2020-05-08 10:53:47 -05:00 committed by GitHub
parent 7a02581159
commit 5d70b2a06f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View file

@ -1,4 +1,3 @@
import React from 'react'
import Link from 'next/link' import Link from 'next/link'
import fetch from 'node-fetch' import fetch from 'node-fetch'
@ -6,7 +5,7 @@ function Index({ stars }) {
return ( return (
<div> <div>
<p>Next.js has {stars} </p> <p>Next.js has {stars} </p>
<Link href="/preact"> <Link href="/preact-stars">
<a>How about preact?</a> <a>How about preact?</a>
</Link> </Link>
</div> </div>
@ -15,7 +14,8 @@ function Index({ stars }) {
export async function getStaticProps() { export async function getStaticProps() {
const res = await fetch('https://api.github.com/repos/zeit/next.js') 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 { return {
props: { props: {
stars: json.stargazers_count, stars: json.stargazers_count,

View file

@ -1,8 +1,7 @@
import React from 'react'
import Link from 'next/link' import Link from 'next/link'
import fetch from 'node-fetch' import fetch from 'node-fetch'
function Preact({ stars }) { function PreactStars({ stars }) {
return ( return (
<div> <div>
<p>Preact has {stars} </p> <p>Preact has {stars} </p>
@ -15,7 +14,8 @@ function Preact({ stars }) {
export async function getStaticProps() { export async function getStaticProps() {
const res = await fetch('https://api.github.com/repos/developit/preact') 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 { return {
props: { props: {
stars: json.stargazers_count, stars: json.stargazers_count,
@ -23,4 +23,4 @@ export async function getStaticProps() {
} }
} }
export default Preact export default PreactStars