I recently started learning NextJS and decided to create my first blog with posts.
The blog is fetching post data from Firebase's Firestore and displays posts on the homepage. There is also an admin page where you can send a new post to the database.
My problem is: when I create a new post in production and send it to the database, the new post doesn't show up until I push something to production again.
I think I need to set up revalidation (for example every 60 sec for testing, once a week on production), but I’m not able to figure it out.
Could someone please help me with this? I use NextJS version 15.1.7
async function getArticles() {
const collectionReference = collection(db, "posts");
const collectionSnapshot = await getDocs(collectionReference);
return collectionSnapshot.docs.map((doc) => ({
id: doc.id,
...doc.data(),
}));
}
export default async function PostsList(){
const articles = await getArticles(); // Načítání článků
const sortedArticles = articles.sort((a, b) => new Date(b.date) - new Date(a.date));
return (
...
)
}
I tried add this line of code:
export const revalidate = 60;
which didn't work
I think I have to use this advice, but I don't know how to apply that in my code: nextjs documentation