TanStackT
TanStack13mo ago
5 replies
verbal-lime

Keep data while is loading using placeholderData

Hey, I was wondering if you could help me with something
I have a page with products and when I delete a product, I need to refetch a specific function to update the list without the deleted product. So I have something like: queryKey: ['my-key', products]

I was using isPending to show an initial loading state, but every time I deleted a product, the loading state would appear. So, I did some research and learned about placeholderData and it worked. I added placeholderData: (prev) => prev, but when there's only one product in the cart and I delete it, the product still appears.

How can I fix this?
Was this page helpful?