rsnext/examples/data-fetch/pages/preact-stars.tsx
Henrik Wenz 16838d5dd4
[Docs] Migrate data-fetch example to typescript (#39852)
## Changelog

- Updated deps
- Migrated to Typescript
- Replaced `div` with `Fragment`

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm lint`
- [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-08-23 14:23:38 +00:00

26 lines
621 B
TypeScript

import Link from 'next/link'
import type { InferGetStaticPropsType } from 'next'
import type { Repository } from '../types/github'
export async function getStaticProps() {
const res = await fetch('https://api.github.com/repos/preactjs/preact')
const json: Repository = await res.json()
return {
props: {
stars: json.stargazers_count,
},
}
}
export default function PreactStarsPage({
stars,
}: InferGetStaticPropsType<typeof getStaticProps>) {
return (
<>
<p>Preact has {stars} </p>
<Link href="/">
<a>I bet Next.js has more stars (?)</a>
</Link>
</>
)
}