getInitialProps doesnt work after pushing to the page? #13371
-
Hey, I'm using next js for my own project and i use it with Material table, when I create an element and redirect to my home page which contain my table, my element didn't show in my table (next doesn't call getIinital props) , for the moment I need to refresh my page to see my new element in my table, should I get help please, just to understand why
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
Beta Was this translation helpful? Give feedback.
-
Your code works for me. When navigating to this page via As a further example: index.getInitialProps = async context => {
if (!context.req) {
return { data: 'logs to the browser when navigated to client side' };
}
// on the server, this runs and logs to your terminal
return { data: 'logs to the terminal when on the server' };
}; |
Beta Was this translation helpful? Give feedback.
Your code works for me.
getInitialProps
is called both on the server and then when navigating to this page vianext/link
it is called again (this time logged to my browsers console).When navigating to this page via
next/link
,context.req
is null therefore this conditional is executed:if (!context.req) { return { data: [] } }
As a further example: