setState method
Replaces this query's state wholesale and notifies its observers and the cache's listeners, with a QuerySetStateAction.
This is how a persistence layer or a devtools panel writes into a query
that already exists. Restoring an entry that does not exist yet goes
through QueryCache.build's state: instead. To change only the data,
use QueryClient.setQueryData.
A success state must carry data (hasData: true), or it is refused
with an ArgumentError in every build mode: an observer built on a
success with no data would cast null to the data type and throw
somewhere that says nothing about where the state came from.
Unlike QueryCache.build, this installs QueryState.fetchStatus as
given, because a fetch may really be running on a live query. A
snapshot restored through here should therefore carry
FetchStatus.idle itself. A fetching or paused status written with
no fetch behind it stays: QueryClient.isFetching counts the entry, and
garbage collection skips it, until a real fetch settles. TanStack Query
behaves the same way.
Implementation
void setState(QueryState<TQueryData> state) {
state.validate();
_dispatch(QuerySetStateAction<TQueryData>(state));
}