Next.js Discord

Discord Forum

Entrypoint of Next.js application

Answered
Ocicat posted this in #help-forum
Open in Discord
Avatar
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:
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?
Image
Answered by Ray
move /app/_app.tsx to /pages/_app.tsx
View full answer

6 Replies

Avatar
Ray
_app.tsx only work for the route inside pages folder
Avatar
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.
Avatar
Ray
move /app/_app.tsx to /pages/_app.tsx
Answer
Avatar
OcicatOP
damn, it worked, thank you so much
I can't believe it was so simple all along
Avatar
Ray
no prob