Reputation: 63
I use RTK query from redux-toolkit. I'm trying to solve race condition and I cannot find a built-in solution to refetch/cancel query while it is executing. I have 1 query (useSomeQuery()
) and 1 mutation (useSomeMutation()
). After mutation is done, query cache should be invalidated. To give some insight - user is changing form and by changing specific inputs (mutation) summary info is refreshed automatically.
Simple scenario that works:
invalidatesTags
to invalidate cache).Race condition scenario that doesn't work:
I've tried to use api.util.getRunningOperationPromise()
inside mutation using onQueryStarted
to abort()
but it seems that it only returns promise for the first load (not for updates).
Is there any built-in solution for that scenario?
Upvotes: 2
Views: 2657
Reputation: 44276
At the moment, there is no good solution for this. Cancelling running queries was considered in the beginning, but could also lead to infinite loops etc., so the safest option was chosen for now.
If you have the drive to look further into this and maybe come up with an alternative solution, please open an issue on github :)
Upvotes: 0