How to retrigger getStaticProps after an update?

Viewed 73

On a personal project related to an online shopping website I have a list of the products page, I'm trying that after I delete a product to refetch the products. I'm using Next.JS and Firebase as a database. The first time when the page is loaded I'm getting the products with getStaticProps

export const getStaticProps = async (context) => {
    const items = Array.from(await getItems({shouldShuffle: false}));
    // more code + return items
}

How can I recall the items var after deleting a product to refetch items?

1 Answers

You can investigate using On-demand Revalidation (Beta), which allows you to manually purge the Next.js cache for a specific page.

This only works for v12.1.0 or more. If you're in a previous version, you will not be able to purge/bust the cache unless you either redeploy or set a revalidate property that specifies the seconds after which an automatic page re-generation will occur.

Related