Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

defining component layout next ts

import { NextPage } from 'next'
import { ComponentType, ReactElement, ReactNode } from 'react'

export type Page<P = {}> = NextPage<P> & {
  // You can disable whichever you don't need
  getLayout?: (page: ReactElement) => ReactNode
  layout?: ComponentType
}
Comment

defining component layout next ts

import type { AppProps } from 'next/app'
import { Fragment } from 'react'
import type { Page } from '../types/page'

// this should give a better typing
type Props = AppProps & {
  Component: Page
}
const MyApp = ({ Component, pageProps }: Props) => {
  // adjust accordingly if you disabled a layout rendering option
  const getLayout = Component.getLayout ?? (page => page)
  const Layout = Component.layout ?? Fragment

  return (
    <Layout>
      {getLayout(<Component {...pageProps} />)}
    </Layout>
  )

  // or swap the layout rendering priority
  // return getLayout(<Layout><Component {...pageProps} /></Layout>)
}

export default MyApp
Comment

PREVIOUS NEXT
Code Example
Typescript :: npm run serve https 
Typescript :: ANGULAR: create component in module 
Typescript :: ganache web3 
Typescript :: what are the common mistakes in testing 
Typescript :: typescript if statement 
Typescript :: what is the use of potential difference 
Typescript :: typescript interface property multiple types 
Typescript :: router params angular 
Typescript :: angular 12 model class 
Typescript :: typescript extend imported namespace 
Typescript :: select constraints in sql 
Typescript :: rails_env production rake assets precompile 
Typescript :: decoDe query string to object javascript 
Typescript :: string of bits to integer java 
Typescript :: how to get child element li beautifulsoup 
Typescript :: javascript block comment 
Typescript :: array in typescript 
Typescript :: adoni migrate 
Typescript :: nest js null exclude 
Typescript :: ng2-dnd not working with angular11 
Typescript :: ipywidgets hide widget 
Typescript :: angular start date end date validation 
Typescript :: chakra ui menu open on hover 
Typescript :: stackoverflow ngbdate angular 
Typescript :: typescript array contains string 
Typescript :: How to disable form control but keep value 
Typescript :: react functional components setstate callback 
Typescript :: typescript require not defined 
Typescript :: across tab localstorage 
Typescript :: callback ref typescript 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =