Update TypeScript API Route example (#44517)
The existing example causes issues with eslint's `eslintimport/no-anonymous-default-export` rule that come pre-enabled with `create-next-app`. Added a name to the api handler function before setting it as the default export. ## 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) Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
This commit is contained in:
parent
08fb7b5bd8
commit
0549a46632
1 changed files with 5 additions and 2 deletions
|
@ -103,7 +103,7 @@ The following is an example of how to use the built-in types for API routes:
|
|||
```ts
|
||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
|
||||
export default (req: NextApiRequest, res: NextApiResponse) => {
|
||||
export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
res.status(200).json({ name: 'John Doe' })
|
||||
}
|
||||
```
|
||||
|
@ -117,7 +117,10 @@ type Data = {
|
|||
name: string
|
||||
}
|
||||
|
||||
export default (req: NextApiRequest, res: NextApiResponse<Data>) => {
|
||||
export default function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<Data>
|
||||
) {
|
||||
res.status(200).json({ name: 'John Doe' })
|
||||
}
|
||||
```
|
||||
|
|
Loading…
Reference in a new issue