Reputation: 446
I have built a website using next.js The guide says that next.js has Two forms of Pre-rendering:
Static Generation (Recommended): The HTML is generated at build time and will be reused on each request. Server-side Rendering: The HTML is generated on each request.
If I am using Static Generation, an let say in my page I have the following code:
export async function getStaticProps({ params }) {
const fetchedData = await axios.get(API_URL);
return {
props: {
fetchedData
}
}
}
Does this mean that this function will be executed only once at the build (when I am deploying the website) and then it means that the data that will be presented on the website will be old data from the date of the deployment? And if so, how can I force next.js to rebuild this page every day?
Upvotes: 1
Views: 2130
Reputation: 493
I just started using next.js. And I'm using firebase hosting. The getStaticProps can be called at request time.
Upvotes: 2
Reputation: 446
OK the answer is Yes, the data that will be presented is the data the was fetched on the build time (e.g the deployment time), so basically if the data on API changes, the site still has the old data.
about the second question - how to force next.js to rebuild the page every period of time - I found a suitable solution for me (because I'm using Vercel hosting):
https://vercel.com/docs/v2/more/deploy-hooks?query=Deploy%20Hooks#
Upvotes: 2