Skip to content

Instantly share code, notes, and snippets.

@elianbarci
Last active June 1, 2022 23:48
Show Gist options
  • Save elianbarci/50669bc57fca9e663c3da0fe3c9ffd00 to your computer and use it in GitHub Desktop.
Save elianbarci/50669bc57fca9e663c3da0fe3c9ffd00 to your computer and use it in GitHub Desktop.
_app,js for multiple Layouts in next.js
import '../styles/globals.scss'
import type { AppProps } from 'next/app'
import type { ReactElement, ReactNode } from 'react'
import type { NextPage } from 'next'
type Page<P = {}> = NextPage<P> & {
getLayout?: (page: ReactNode) => ReactNode;
};
type Props = AppProps & {
Component: Page;
};
function MyApp({ Component, pageProps }: Props ) {
const getLayout = Component.getLayout ?? ((page: ReactNode) => page);
return getLayout(<Component {...pageProps}></Component>)
}
export default MyApp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment