Skip to content

Commit

Permalink
Update with-zeit-fetch example to use SSG (#11026)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruisaraiva19 committed Mar 13, 2020
1 parent b092ff7 commit 9d9496e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions examples/with-zeit-fetch/pages/index.js
Expand Up @@ -2,21 +2,21 @@ import React from 'react'
import Link from 'next/link'
import fetch from '../fetch'

function Index(props) {
export default function Index({ stars }) {
return (
<div>
<p>Next.js has {props.stars} ⭐️</p>
<p>Next.js has {stars} ⭐️</p>
<Link href="/preact">
<a>How about preact?</a>
</Link>
</div>
)
}

Index.getInitialProps = async () => {
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
return { stars: json.stargazers_count }
return {
props: { stars: json.stargazers_count },
}
}

export default Index
12 changes: 6 additions & 6 deletions examples/with-zeit-fetch/pages/preact.js
Expand Up @@ -2,21 +2,21 @@ import React from 'react'
import Link from 'next/link'
import fetch from '../fetch'

function Preact(props) {
export default function Preact({ stars }) {
return (
<div>
<p>Preact has {props.stars}</p>
<p>Preact has {stars}</p>
<Link href="/">
<a>I bet Next.js has more stars (?)</a>
</Link>
</div>
)
}

Preact.getInitialProps = async () => {
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
return { stars: json.stargazers_count }
return {
props: { stars: json.stargazers_count },
}
}

export default Preact

0 comments on commit 9d9496e

Please sign in to comment.