DEV Community 👩‍💻👨‍💻

Discussion on: Next.js E-Commerce Tutorial: SPA Example

payapula profile image

Great Article. 👏🏼

One question on the getStaticProps and getServerSideProps.

getStaticProps would be called only at build time, since we are using that here, if we update our database with new products it would be fetched only on fresh build.

If we have used getServerSideProps with API routes, for the above use case, the new products would be reflected on a page reload/new request. Is my understanding is correct?

pierreguillaumelaurin profile image
Pierre-Guillaume Laurin Author

@payapula much thanks! 🙇

Indeed getStaticProps will be called at build time, independently of database updates. Although you can use the  revalidate option to refresh the page after a certain delay.

getServerSideProps will pre-render the page on each request as you said, which is most often a good approach if your use case requires very frequent database updates.

So your understanding was indeed correct! 🙂