Keep data & error while refetch is loading
Hello! I'm trying to utilize the refetchInterval to poll on an endpoint, and utilize the data & error in the template. However it seems like whenever a refetch is initiated, the data and error props from the useQuery call are cleared until loading is complete, which results in the content blinking out for a short time. Is there a way to wait to update those until after the new fetch resolves?
5 Replies
blank-aquamarineOP•4y ago
The best I've been able to do is set up my own data and error variables with useState and call the setters from the onError and onSuccess handlers
rare-sapphire•4y ago
Shouldn't be the case. Show a codesandbox reproduction please
blank-aquamarineOP•4y ago
After some more testing it seems like data holds its value as expected, but error does not:
https://codesandbox.io/s/quizzical-mopsa-16zndj?file=/pages/index.js
Roundaround
CodeSandbox
quizzical-mopsa-16zndj - CodeSandbox
quizzical-mopsa-16zndj by Roundaround using @tanstack/react-query, @tanstack/react-query-devtools, axios, next, react, react-dom
rare-sapphire•4y ago
Yes that's expected
blank-aquamarineOP•4y ago
Okay so then if I want to persist the error until the next response arrives the only way I can do it is with a separate useState and the onError/onSuccess callbacks, right?