Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update with-zeit-fetch example to use SSG #11026

Merged
merged 1 commit into from Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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