最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What does NextPage in Next.js do? - Stack Overflow

programmeradmin2浏览0评论

I just started using TypeScript with Next. What does this do? import { NextPage } from 'next'; export const Page: NextPage = () => {} I looked at the docs but it does really give a good explanation in what it does.

I am guessing by the name that it routes pages. Can someone please explain what this does?

Thank you.

I just started using TypeScript with Next. What does this do? import { NextPage } from 'next'; export const Page: NextPage = () => {} I looked at the docs but it does really give a good explanation in what it does.

I am guessing by the name that it routes pages. Can someone please explain what this does?

Thank you.

Share Improve this question asked Dec 9, 2021 at 8:43 cyberAnncyberAnn 4712 gold badges7 silver badges22 bronze badges 2
  • Does this help answer your question: Usage of NextPage type in Next.js? – juliomalves Commented May 29, 2022 at 16:02
  • Its not next page, but Next™ Page – Coloured Panda Commented Jan 31, 2024 at 8:09
Add a ment  | 

2 Answers 2

Reset to default 10

My advice is to start here, but in brief:

import { NextPage } from 'next';

export const Page: NextPage = () => {}

NextPage is a type exported by NextJS. When we write Page: NextPage we're saying that our Page ponent is of type NextPage.

import { NextPage } from 'next'; : This line imports the NextPage type from the next package. The NextPage type is a generic type provided by Next.js for defining the type of a Next.js page ponent.

When you create a page in Next.js, you typically define it as a React ponent. The NextPage type is a type alias for a React ponent that is a Next.js page. It includes properties specific to Next.js pages, such as getStaticProps, getServerSideProps, and others used for data fetching during page rendering.

So, in summary, the code you provided is creating a Next.js page ponent using TypeScript. It is defining a constant named Page with the type NextPage and providing the logic for your page within the arrow function. This is a mon pattern when working with Next.js and TypeScript to ensure type safety and provide better development tooling support.

发布评论

评论列表(0)

  1. 暂无评论