Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify and convert
with-vercel-fetch
example to TypeScript (#43403)
Simplified the example to just the specific feature, and converted to TypeScript. - `node-fetch@2` is either polyfilled by Next.js or a peerDep of `@vercel/fetch`, I can't quite tell, but either way it can be removed from the dependencies. ## Documentation / Examples - [X] Make sure the linting passes by running `pnpm build && pnpm lint` - [X] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
- Loading branch information
Showing
9 changed files
with
59 additions
and
53 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// For simplicity we are creating our own types here. | ||
// If you want the full types check out: | ||
// https://github.com/octokit/openapi-types.ts | ||
export type Repository = { | ||
id: number | ||
name: string | ||
full_name: string | ||
stargazers_count: number | ||
private: boolean | ||
} & Record<string, unknown> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { InferGetStaticPropsType } from 'next' | ||
import type { Repository } from '../github' | ||
import createFetch from '@vercel/fetch' | ||
|
||
export async function getStaticProps() { | ||
const fetch = createFetch() | ||
const res = await fetch('https://api.github.com/repos/vercel/next.js') | ||
const repo = (await res.json()) as Repository | ||
|
||
return { props: { stars: repo.stargazers_count } } | ||
} | ||
|
||
export default function HomePage({ | ||
stars, | ||
}: InferGetStaticPropsType<typeof getStaticProps>) { | ||
return ( | ||
<div> | ||
<p>Next.js has {stars} ⭐️</p> | ||
</div> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve", | ||
"incremental": true | ||
}, | ||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "github.d.ts"], | ||
"exclude": ["node_modules"] | ||
} |