I am using nextjs version 12.1.6
, react-dom version 18.0.5
, next-auth 4.6.1, I have an application with 2 routes at the moment, an index page and a login page, when I route from the index page to the login page and vice versa, my whole app rerenders, I have react-profiler and the given reason is context change, I assume its have to do something with the SessionProvider
from next-auth
but why it rerenders my whole app?
as you can see I have a HeaderComponent that did NOT rerendered, this is because I used React.memo
on it, but I dont want to wrap all my components in React.memo
, also this component is used inside on a Layout component pages/_app.tsx
my _app.tsx
function App({ Component, pageProps }: AppProps) {
return (
<>
<Head>
<title>foo</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>
<SessionProvider session={ pageProps.session }>
<LayoutComponent>
<Component {...pageProps} />
</LayoutComponent>
</SessionProvider>
</>
);
}
also I am using nextjs Link
jsx element for routing
my LayoutComponent:
const LayoutComponent = ({ children }: PropsWithChildren) => {
return (
<>
<HeaderComponent
homePath='/'
signinPath='/auth/signin'
aboutPath='/about'
/>
<main>
{ children }
</main>
<FooterComponent />
</>
);
}
export default LayoutComponent;