Unverified Commit 0234e6d5 authored by jpveilleux's avatar jpveilleux Committed by GitHub

Added type to Page Component for TypeScript (#36608)

* Added type to Page Component for TypeScript

Following this tutorial, I noticed that TS was complaining that "getLayout" did not exist on Page. That is normal since Page is typed as NextPage. I simply exported the new type we create in "_App.tsx" and used it as the return type for Page. This will probably help others seeing that red in their editors and perhaps being confused.

* Small linting change

* Apply suggestions from code review

* Update layouts.md

* lint fix

* update type
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent 95fb221e
......@@ -102,11 +102,10 @@ When using TypeScript, you must first create a new type for your pages which inc
import type { ReactElement } from 'react'
import Layout from '../components/layout'
import NestedLayout from '../components/nested-layout'
import type { NextPageWithLayout } from './_app'
export default function Page() {
return {
/** Your content */
}
const Page: NextPageWithLayout = () => {
return <p>hello world</p>
}
Page.getLayout = function getLayout(page: ReactElement) {
......@@ -116,6 +115,8 @@ Page.getLayout = function getLayout(page: ReactElement) {
</Layout>
)
}
export default Page
```
```tsx
......@@ -125,7 +126,7 @@ import type { ReactElement, ReactNode } from 'react'
import type { NextPage } from 'next'
import type { AppProps } from 'next/app'
type NextPageWithLayout = NextPage & {
export type NextPageWithLayout = NextPage & {
getLayout?: (page: ReactElement) => ReactNode
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment