Unverified Commit 5d70b2a0 authored by Luis Alvarez D's avatar Luis Alvarez D Committed by GitHub

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

parent 7a025811
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 }) { ...@@ -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 }) { ...@@ -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,
......
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 }) { ...@@ -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() { ...@@ -23,4 +23,4 @@ export async function getStaticProps() {
} }
} }
export default Preact export default PreactStars
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment