Repository navigation
Replies: 2 comments
|
Yes, this is totally fine — it's a recognized pattern called the "push approach" to cache seeding, and TkDodo wrote a whole post about it: Seeding the Query Cache. The TanStack docs also cover it in the Prefetching guide. The idea is exactly what you're doing: a single API call returns data for multiple queries, so you write the related data into the cache proactively instead of making extra network requests later. A few things worth knowing with your specific setup:
The The exception: if you have queryClient.setQueryDefaults(invoiceSettingsQueryKeys.detail(id), {
gcTime: 5 * 60 * 1000, // 5 minutes
});
When a component mounts with queryClient.setQueryDefaults(invoiceSettingsQueryKeys.detail(id), {
staleTime: 60 * 1000,
});One thing to check: data structure completeness This only works cleanly if the Overall, the pattern is solid. The |
|
One cancellation caveat to add to the cache-seeding answer: the write to the invoice-settings key is independent of the document query's lifecycle. Cancelling the document query does not roll back a Your service receives const data = await DocumentSideService.getDocumentData(efinGuid!, signal);
signal.throwIfAborted();
// Build the store and seed the related cache entry here.Use this where your supported runtime provides I reproduced the distinction with Query Core 5.108.4: start a parent query with a deferred service result, cancel the parent, then resolve the service. The parent's result is discarded, but an unguarded child AI-assisted reply; the cancellation/cache behavior was checked locally, not against your service implementation. |
Uh oh!
There was an error while loading. Please reload this page.
Hello I want to ask if something like that is fine todo:
i.e. the
client.setQueryData.All reactions