Having a hard time finding a good answer/ solution for this problem.
I have a POSTS list component that allows to delete individual POST rows.
I'm using a run of the mill queryMutation
for deletion purposes:
IMPLEMENTATION
deletePostById: build.mutation<{ success: boolean; id: number }, number>({
query(id) {
return {
url: `post/${id}`,
method: 'DELETE',
}
},
invalidatesTags: (result, error, id) => [{ type: 'Posts', id }],
})
USAGE
const [deletePost, { isLoading: isDeleting, error: deletionError }] = useDeletePostByIdMutation();
PROBLEM DESCRIPTION
Within the list component the individual row has an icon to delete that Post - while isDeleting
I'm showing a spinner, which is also showing just fine - however, when the Post is deleted the auto-refetching of RTKQ kicks in to get the now updated Posts from the server - isDeleting
is no longer true though.
This leaves a small time window in which the Post row is not showing any spinner but also is not removed yet from the Posts list.
Once the refetched data of all Posts has successfully returned the deleted Post row gets removed from the list.
How can I sustain the spinner animation from deleting the individual Post till the removal after the automatic refetching of RTKQ has finished?
Thanks
isLoading
(orisFetching
) of the list per se. I just want to piggy back on the fact, that the list is loading and hitch theisFetching
of the deleteQuery on it to sustain the linked animation when deleting that row. can I keepisFetching
of the deleteQuery true based on the listsisFetching
query? that's what I meant with sustaining. Thanks β Matheny