TanStackT
TanStack3y ago
15 replies
verbal-lime

What method should i use to clean up the data before ovewrite it? trying with setQueryData to null.

Hello . I have a react and node project , and i encountered a problem by applying filters to my data , first i obtain general products for my page to render , then i want to apply filters to those products, and clean the previous products and only display the new ones.
I tried that by using the setQueryData to null and then setting the data to the one i needed, and it works in a weird way, cause the first time i click the button it renders me the right products but also the previous ones , and when i click it again , it works perfectly, it deletes the products i got on my first render and only shows me the filtered ones.
¿ What method should i use to clean up the data before ovewrite it?
I have tried refetchQueries,invalidateQueries,cancelQueries, but none of those works (I know i´m probably not using them correctly, i´m new using reactQuery).
Or is it a better way to do what i want ? To set the new queryData ("productos") to just the new ones for the first click.
I would love to put a codesanbox example, unfortunately i´m having a lot of problems trying to do that. }
I´m sorry for the language errors , english is not my native language.

Thanks a lot to the guy that told me to put here the questions and i'm sorry if i'm making a mistake again.

If more code is needed for understaing the problem, please let me know , thanks
carbon.png
Was this page helpful?