How to setQueryState to error
I'm using WebSockets to push new data to the client and calling
QueryClient.setQueryState
with the new data to update useQuery hooks for that query all over my app.
But what about when the state I want to update with is an error? How do I inform the QueryClient of an error?5 Replies
magic-amberOP•15mo ago
I can invalidate the query and wait for the QueryClient to run the queryFn again for now, but it will be a little late; the same WebSocket message carries updates for other query subscriptions and I'd love to be able to update them all at the same time.
Tracing through the code I think this will happen during the current tick, so not bad
what I'm hoping for is "don't make React do a bunch of work we're going to throw away"
and I just hope Reat 18's automatic batching of setState calls will provide this
Ohhh I can just reach in and grab the Query objects and call .setState() on them huh
It feels too internals-y, I'd like to call dispatch but that's private
I'm unclear on exactly the public API is but it feels like I've stepped beyond it
And I'm unclear on the implications of dispatching a
setState()
event instead of an error
eventxenial-black•15mo ago
This is not intended
magic-amberOP•15mo ago
@M00LTi it sounds like if I want this I should make a feature request for a stable API for this?
xenial-black•15mo ago
Or you make a workaround: invalidate the query and make it fetch the error itself
magic-amberOP•15mo ago
this probably works, need to reason about whether the errors get propagated the same tick or not