Next.js Discord

Discord Forum

Infinite pagination & cache revalidation

Answered
Pollock posted this in #help-forum
Open in Discord
PollockOP
Hello guys,

I created a page that shows data in a cards layout and implemented an automatic pagination through scrolling. On each card, user has an option to delete that card, which triggers a server action and delete the item from DB. The server action also calls revalidatePath.

However, this flow works as expected only for items on a first page, when you scroll down to load data from next pages, the card doesn't disappear after the delete action.

Which is kind of expected behaviour, since after the server action the page is "I guess" softly refreshed and data are refetched just for the first page. I'm struggling to find a solution to correctly update the whole page (or the actual paginated part that changed). What would be a proper/recommended way of reflecting the delete action?
Answered by Pollock
managed to get it working with a help of a global state
View full answer

4 Replies

PollockOP
Adjusted the description a bit...
PollockOP
PollockOP
managed to get it working with a help of a global state
Answer
PollockOP
updated the repo with a solution