defining component layout next ts code example
Example 1: defining component layout next ts
import type { AppProps } from 'next/app'
import { Fragment } from 'react'
import type { Page } from '../types/page'
type Props = AppProps & {
Component: Page
}
const MyApp = ({ Component, pageProps }: Props) => {
const getLayout = Component.getLayout ?? (page => page)
const Layout = Component.layout ?? Fragment
return (
<Layout>
{getLayout(<Component {...pageProps} />)}
</Layout>
)
}
export default MyApp
Example 2: defining component layout next ts
import { NextPage } from 'next'
import { ComponentType, ReactElement, ReactNode } from 'react'
export type Page<P = {}> = NextPage<P> & {
getLayout?: (page: ReactElement) => ReactNode
layout?: ComponentType
}