I have three pages that I want to share data between (these are the core of the web app) but I also have a bunch of blog pages that don't care about that data. Everywhere I've looked suggests putting the Provider in the _app.tsx
file. If I understand that correctly if I wrapp MyApp
with the provider, if someone goes straight to www.myurl.com/blog/my-blog-1 (from google), that will cause the provider to run its functions; even if that page won't call useContext
How do I only wrap three pages in the Provider and leave out the blog pages?
For example:
- www.myurl.com -> I want this to use the shared data from the provider
- www.myurl.com/my-functionality -> I want this to use the shared data from the provider
- www.myurl.com/profile-> I want this to use the shared data from the provider
- www.myurl.com/blog/* -> I don't want this to call the functions in the auth provider
Here's what my _app.tsx
looks like:
import { AppProps } from 'next/app'
import '../styles/index.css'
export default function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}
UserProvider
and you navigate to other page that's using the same layout, I doubt the user will stay in the context, will it? – Selfseeker