TanStackT
TanStack3y ago
3 replies
uncertain-scarlet

Update multiple keys after useQuery call

Hi,

Is there any way to update the cache of multiple keys after a useQuery call.

Tell me if I am thinking in the wrong way but it seems that this is necessary.

Here is my use case:

I am getting a list of an entity by using a list endpoint using key: ['list'] and showing it in the page. User clicks one of the entity and I am showing the detail of an entity using the key ['entity', {idOfEntity}]. if the indivudual entity in the response of list of entity is enough to show the detail I don't need to refetch the individual.
In that case I want to show the detail by using the list entities so I want to assign the cache of the individual cache by using the list entities.

or another use case:

I have a batch get endpoint which can get the indivual entities with only one request. I don't want to keep a cache for the batch result but I want to spread the result to individual keys so that the individual entities can be gathered by individual keys.

is it possible and if it is ok how should I proceed? Should I use useMutate for my second use case or is there any other mechanism I should follow.
Was this page helpful?