Entrypoint of Next.js application
Answered
Ocicat posted this in #help-forum
OcicatOP
Hello, I have problem with understanding how to use providers around the entrypoint. I ignored this issue and wrapped them around /pages components and they worked fine. But now it came to haunt me and I need to fix this. I attached the file structure.
This is my _app.tsx:
Whenever I use it like this
The provider just doesn't work. It doesn't register in the structure.
How do I go about this?
This is my _app.tsx:
export default function MyApp({Component, pageProps}: any) {
const getLayout = Component.getLayout || (
(page: string | number | boolean | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | PromiseLikeOfReactNode | null | undefined) => (
<RootLayout>{page}</RootLayout>
)
)
return getLayout(<Component {...pageProps} />)
}
Whenever I use it like this
<RootLayout>
<Provider>
{page}
</Provider>
</RootLayout>
The provider just doesn't work. It doesn't register in the structure.
How do I go about this?
6 Replies
OcicatOP
That's what I wanna do. I want all routes in
/pages
to have a set of providers, but when I use it in _app.tsx
it doesn't render and I need to wrap every page to do so.Answer
OcicatOP
damn, it worked, thank you so much
I can't believe it was so simple all along