TanStackT
TanStack2y ago
2 replies
wet-aqua

Optimistic updates without re-rendering everything?

Hi, I have a shopping cart. When a user changes the quantity of some item, I'd like to do an optimistic update along with the mutation.
If I call:
queryClient.setQueryData(['cart'], /* shopping cart where relevant item is modified */);

All shopping cart items are re-rendered, each component is created from scratch, scroll position is lost.
Is there any way to do the update a single property of one item without re-rendering everything?

SolidJS has a SetStore API function for fine-grained updates (see docs - tutorial and api reference). Does TanStack Query expose this function?
Was this page helpful?