Next.js Discord

Discord Forum

Revalidate with Infinite scroll component

Unanswered
Saint Hubert Jura Hound posted this in #help-forum
Open in Discord
Saint Hubert Jura HoundOP
Hello, I would like to make Twitter (X) with Nextjs. For the homepage I use the https://www.npmjs.com/package/react-infinite-scroll-component npm package which allows to make an infinite scroll. I put a server action in the next function props. I have a list of tweets, with a like button on each. The problem is that when I like a tweet, it calls a server action, but in this one it does a revalidateTag, which therefore reloads the whole component. In the case where I scroll to load other tweets, when I like a tweet, it will return to the initial state, remove at the client level the tweets that I loaded by scrolling.
I don't know how to do that when I like a tweet, it only revalidates the likes of the tweet that I liked.
I also use the useOptimistic hook for the like button.

2 Replies

European anchovy
@Saint Hubert Jura Hound are you still working on that ?
I am working on the same kind of project. I simply have a useState for the likes count and another one for whether the authenticated user has liked the tweet or not. if you really want to use the experimental useOptimistic hook, I can give you a link to a tutorial that shows you how to do that.