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 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,
......
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
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