DEV Community

Cover image for Next Js SSR [getServerSideProps]
itishprasad30
itishprasad30

Posted on

Next Js SSR [getServerSideProps]

How Ssr code will work in Next js

  • If a page uses Server-side Rendering, the page HTML is generated on each request.

  • Server-side Rendering: The HTML is generated on each request. To make a page use Server-side Rendering, export getServerSideProps. Because Server-side Rendering results in slower performance than Static Generation, use this only if absolutely necessary.

const App = ({data}) => {
return (
    <>
    //jsx  will go here // render the data
    </>
  )
}

export async function getServerSideProps() {
//fetching data from some api
const res  = fetch('https://someapi.com/get')
const data = await res.json()

return {
     props:{
           data;
          }
     }
}

export default App;

Enter fullscreen mode Exit fullscreen mode

Discussion (0)