How to add getLayout property to Component, nextJS 12.3

Help me, NextJs12 --> NextJs12.3, don't know how to use getLayout,
4 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
birchrust
birchrustOP3y ago
Running smoothly, thank you very much!
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
jeff.kershner
jeff.kershner2y ago
After looking around the discord, I found this that works:
import type { ReactElement, ReactNode } from 'react';
import type { NextPage } from 'next'
import type { AppProps } from 'next/app'
import { type AppType } from "next/app";
import { type Session } from "next-auth";
import { SessionProvider } from "next-auth/react";

import { api } from "~/utils/api";

import "~/styles/globals.css";


export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
getLayout?: (page: ReactElement) => ReactNode
}

type AppPropsWithLayout = AppProps & {
Component: NextPageWithLayout
}

const MyApp: AppType<{ session: Session | null }> = ({Component, pageProps: { session, ...pageProps }}: AppPropsWithLayout) => {
const getLayout = Component.getLayout ?? ((page) => page);
const layout = getLayout(<Component {...pageProps} />);

return (
<SessionProvider session={session}>
{ layout }
</SessionProvider>
);
};

export default api.withTRPC(MyApp);
import type { ReactElement, ReactNode } from 'react';
import type { NextPage } from 'next'
import type { AppProps } from 'next/app'
import { type AppType } from "next/app";
import { type Session } from "next-auth";
import { SessionProvider } from "next-auth/react";

import { api } from "~/utils/api";

import "~/styles/globals.css";


export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
getLayout?: (page: ReactElement) => ReactNode
}

type AppPropsWithLayout = AppProps & {
Component: NextPageWithLayout
}

const MyApp: AppType<{ session: Session | null }> = ({Component, pageProps: { session, ...pageProps }}: AppPropsWithLayout) => {
const getLayout = Component.getLayout ?? ((page) => page);
const layout = getLayout(<Component {...pageProps} />);

return (
<SessionProvider session={session}>
{ layout }
</SessionProvider>
);
};

export default api.withTRPC(MyApp);
Want results from more Discord servers?
Add your server