Entrypoint of Next.js application
Answered
Ocicat posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
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?
![Image](https://cdn.discordapp.com/attachments/1198595181621026888/1198595181788807259/image.png?ex=65bf79c0&is=65ad04c0&hm=1143712ca017247e69b4cba2024ef35ec8e0583d6440afe85b577efcc41a6c73&)
6 Replies
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
_app.tsx
only work for the route inside pages
folder![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
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](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
move
/app/_app.tsx
to /pages/_app.tsx
Answer
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
OcicatOP
damn, it worked, thank you so much
I can't believe it was so simple all along
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
no prob