-
Notifications
You must be signed in to change notification settings - Fork 166
Description
One thing I love about TanStack DB is that it has such parallels to TanStack Query that it's simple to swap from Query to DB, making it easy to adopt incrementally. One significant challenge though is that while Query deduplicates queries by queryKey, DB does not. That means we can't just swap our useVendorsQuery for a useLiveVendorsQuery; we need to be careful that useLiveVendorsQuery isn't called 20 times on the same page (e.g. in a table view), or else the query will run 20 times.
TanStack Query solves this problem with a QueryCache and a QueryObserver for every call to the same key. It uses an array for the key because they need to think about query invalidation, but a simple string would probably be fine here because we don't need to worry about invalidation.
We can work around this by hoisting the query higher up the component tree and share the results explicitly, but it makes adoption a little less simple.