Setting cache data to undefined on error in useQuery
Hello,
Is it possible to set query data in cache to undefined using useQuery if error is thrown by queryFn?
Current behavior - previous data in cache is returned on error. I know I can leverage this by simply adding catch block in my queryFn and return null but then error is not received by useQuery will show isError status as false. Also I can check for isError while rendering and replace data with undefined, but for simplicity I just want to always have returned undefined and query data reset in cache to undefined on error. Is there any option in useQuery to do that or I should stick with UI rendering depending on isError status?
Also, I noticed if I return undefined in catch block of my queryFn it will not treat it as new data and return previous data, so I need to use null instead. Is this default behavior that you can not set data as undefined?
0 Replies