0

When rendering page.js in next js, getServerSideProps is not working correctly. H1 tag is empty and 'test' is not logged to the console for this code inside app/page.js:

export const getServerSideProps = async () => {
  console.log('test')
  return { props: { data: 'test' } }
}

export default async function Home({ data }) {
  return (
    <main>
      <h1>{data}</h1>
    </main>
  )
}

Any idea what the problem might be?

I have tried restarting the server, opening in incognite browser and replacing getServerSideProps with getStaticProps which didnt change anything.

  • 1
    `getServerSideProps` is not supported while using `app` directory. Refer migration docs: https://nextjs.org/docs/app/building-your-application/upgrading/app-router-migration#server-side-rendering-getserversideprops – brc-dd Jul 09 '23 at 07:50
  • Hello @brc-dd can you please Elaborate it, I don't get getServerSideProps is not supported while using app directory. How can i use getServerSideProps if then ? – K Kumar Aug 18 '23 at 05:27

2 Answers2

1

As the other answer/comments have mentioned, getServerSideProps are not supported in Next13 if using app directory. Adding on to that, you can migrate the function in the following manner:

async function getDate() {
  console.log('test');
  return 'test';
}

export default async function Home() {
  const data = await getData()
  return (
    <main>
      <h1>{data}</h1>
    </main>
  )
}
Krushnal Patel
  • 422
  • 2
  • 14
0

getServerSideProps is not supported while using app directory. Refer migration docs: https://nextjs.org/docs/app/building-your-application/upgrading/app-router-migration#server-side-rendering-getserversideprops