Problem with queryFulfilled #3606
Unanswered
pencil-user
asked this question in
Q&A
Replies: 1 comment
-
I don't think that this code is correct: try {
const _ID = await queryFulfilled
dispatch(
apiSlice.util.updateQueryData('getStuff', undefined, (stuff) => {
const index = stuff.findIndex(x => x.ID === ID)
if (index > -1) (stuff.splice(index, 1))
})
)
} catch { }
"What is happening is that when I click delete item, deleting item... loader shows then disapears, and then item gets removed a bit later. Functionality I want is that Item gets removed at the same time loader disappers (i.e. simultaneously)." Is the result of the refetch implied by the cache invalidation. Not the pessimistic update. Try this instead: const { data: _ID } = await queryFulfilled |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
Theres's something that is not clear to me regarding RTK Query and pessimistic updates. Say that we have this situation. There is an Api that gets list of stuff and can delete individual items. Then there is a stuff list displaying individual items each with delete button and its own mutation hook:
ApiSlice:
Components:
What is happening is that when I click delete item, deleting item... loader shows then disapears, and then item gets removed a bit later. Functionality I want is that Item gets removed at the same time loader disappers (i.e. simultaneously).
Item does get deleted immediately if I comment out await queryFulfilled line but then it is just optimistic update and loader is never shown. But basically the problem is that queryFulfilled takes too long (or loader shows too short)
Other than not being able to figure this out RTK Query is excelent.
Beta Was this translation helpful? Give feedback.
All reactions