Tanstack optimistic update for deleting a 'template'. I cant seem to figure out whats wrong..

Hi yall! At my work we have some big files called templates. They can go up to 10 mb (yes they are that big) and when deleting one it sucks for the UX. So I am implementing optimistic updates from tanstack query but I seem to be doing something wrong and my guess is because of my lack of knowledge.. Other info: - I have a TemplateProvider function that caches data under the cache key composed of an array of values ( ["templates", pageNumber, folderId || "all", search],) - I have a useRemoveTemplate() that tries to optimistically update the ui by following the tanstack docs (https://tanstack.com/query/v4/docs/guides/optimistic-updates) - I added a picture of the table that I am trying to optimistically update Problem: When I queryClient.setQueryData(cacheKey, () => deletedTemplateList); in my useRemoveTemplate() my Template provider does not recognize the new values and reads 'undefined' why? 😦 Thanks in advance for thinking along
Optimistic Updates | TanStack Query Docs
When you optimistically update your state before performing a mutation, there is a chance that the mutation will fail. In most of these failure cases, you can just trigger a refetch for your optimistic queries to revert them to their true server state. In some circumstances though, refetching may not work correctly and the mutation error could ...
1 Reply
ibramsterdam
ibramsterdamOP•3y ago
Good morning! Giving this post a bump Resolved it >.<
Want results from more Discord servers?
Add your server