My app is built using NextJs with Typescript and using the react-bootstrap library for components. I keep getting an error that says
When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are generated between the client and server.
I tried to include the SSRProvider that comes with react-bootstrap, but it doesn't seem to be working no matter where I put it in my _app.tsx
file. Anyone know how to resolve this? My UI keeps breaking when reloading the page.
import type { NextComponentType } from 'next';
import { AppContext, AppInitialProps, AppLayoutProps } from 'next/app';
import { ReactNode } from 'react';
import { ThemeProvider } from 'styled-components';
import theme from '../styles/theme';
import { SSRProvider } from 'react-bootstrap';
const MyApp: NextComponentType<AppContext, AppInitialProps, AppLayoutProps> = ({
Component,
pageProps,
}: AppLayoutProps) => {
const getLayout = Component.getLayout || ((page: ReactNode) => page);
return (
getLayout(
<SSRProvider>
<ThemeProvider theme={theme}>
<Component {...pageProps} />
</ThemeProvider>
</SSRProvider>
)
)
}
export default MyApp;
Fixed this by wrapping the entire return statement in the <SSRProvider>
tag. Last time I tried that, I forgot to wrap the getLayout()
statement in curly braces. Here is the code for anyone running into the same issue.
return (
<SSRProvider>
{getLayout(
<ThemeProvider theme={theme}>
<Component {...pageProps} />
</ThemeProvider>
)}
</SSRProvider>
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With