T
TanStack3y ago
genetic-orange

Do I really need useMutation?

I have a page with couple of dialogs to change the data in it (CRUD, but there are several different items in it). In the actual page contents are inside a useQuery isLoading clause and it should show a spinner when this is true. It seems like data fetching is done when I e.g. delete something (I run invalidateQueries after the operation) but the page won't update until I force it (visit another window). I though isLoading should make it update?
3 Replies
graceful-beige
graceful-beige3y ago
I don't understand the question. please show a reproduction
genetic-orange
genetic-orangeOP3y ago
That would be quite impossible as that would mean letting people delete data from my database without authorisation. Reproduction would also pretty much necessitate that or creating the database somewhere else. I try to explain in more detail: I have a Work view. It uses useQuery() and gets the isLoading state. Inside the tsx code I have { isLoading ? <ProgressSpinner> : <div>...</div>} This query is called Work + work.id. (The key that is) Inside the Work page I have a list of Editions whose contents are loaded with the same query. For each Edition there is an edit and delete button. When I click the Delete button the delete functionality is run. This includes a queryClient.invalidateQueries call. I can see from the Query Tools that work data is refreshed. But the page doesn't show the changes. It's like isLoading never changes state?
wee-brown
wee-brown3y ago
I believe invalidateQueries triggers a background refetch. The data is fetched in the background and should be updated in the ui, but isLoading will remain false. isLoading is only true when there is no data in cache. You may be looking for isFetching instead.

Did you find this page helpful?