最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

firebase - How to revalidate Firestore data in NextJS server component? - Stack Overflow

programmeradmin6浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论