You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I use only the code below then I can use getInitialProps on every page and return data to the component. Fine, but getServerSideProps doesn't seem to run, i.e. no data is returned.
_app.js
constMain=({ Component, pageProps, store })=>{useEffect(()=>{// Remove the server-side injected CSS.constjssStyles=document.querySelector('#jss-server-side');if(jssStyles){jssStyles.parentElement.removeChild(jssStyles);}},[]);return(<Providerstore={store}><Head><title>Main</title></Head><ThemeProvidertheme={theme}><CssBaseline/><Component{...pageProps}/></ThemeProvider></Provider>);};
If I add this code below then I can use getServerSideProps on pages and return data to the component, but now getInitialProps doesn't run. I am not using them both at the same time.
Main.getInitialProps=async(appContext)=>{// calls page's `getInitialProps` and fills `appProps.pageProps`constappProps=awaitApp.getInitialProps(appContext);return{ ...appProps};};
I want to be able to use either getInitialProps or getServerSideProps on any page, not only one.
Can someone explain why this is happening and how to fix.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
If I use only the code below then I can use
getInitialProps
on every page and return data to the component. Fine, butgetServerSideProps
doesn't seem to run, i.e. no data is returned._app.js
If I add this code below then I can use
getServerSideProps
on pages and return data to the component, but nowgetInitialProps
doesn't run. I am not using them both at the same time.I want to be able to use either
getInitialProps
orgetServerSideProps
on any page, not only one.Can someone explain why this is happening and how to fix.
Beta Was this translation helpful? Give feedback.
All reactions