TanStackT
TanStack6mo ago
9 replies
wispy-olive

Continuous re-fetching of data with changes to existing items

Hi There,

I have one use-case which I don't really have a good idea how to handle it. The usecase is a photo gallery which updates in "realtime". All photos can (theoretically) change all the time on server side (new photos or changes to existing photos like caption or the status). Any change is indicated by a "lastModified" date for each photo.

At the moment without Tanstack Query, I fetch the current list of photos, store it in the state and remember the "highest" last modified date. Every few seconds I fetch the changes since the remembered lastModified date from the server again (it will just return changed ones), go through the results and update the existing items in the state.

How to handle this with Query? I don't want to always fetch the complete list again, since normally there are few changes. I looked into "infinite queries" but that looks like more suitable for pages without changes on existing items.

I would like to use Query, since I have that everywhere else and I like the other features it has.

Any idea or direction? Thx!!
Was this page helpful?