useWatch in React and client.watch
anywhere run a query and deliver its Result as it updates.
What wakes a watch
- A write to a fact the query read with
ctx.get, or into a selection it read withctx.list,ctx.pageorctx.count. - A change to the fact’s presence for a query that read it with
ctx.has. - A change to the caller’s grants or to the guards the query’s entry depends on: authority is a read too, so a revoked grant reaches an open watch.
One state at a time
Each query evaluation reads one committed version. A successful live answer carries the read’sversion when the host supplies it. On an HTTP
client, identical watches in the same frame share a stream when the query,
arguments and seen match. Distinct watches use separate streams and
catch up independently. After a checkout changes both a cart and its
stock, a cart watch can show the new count while a stock watch still shows
the earlier version.
When values must agree, return them from one query and watch that answer.
For example, read the cart count and stock in the same query and return
both. That also gives time-sensitive reads the same evaluation instant.
For separate one-off reads, you can select a retained version.
Reconnect applies to each stream. A normal reconnect without a continuation
uses the watch’s seen, if supplied. If the server furnished a resume
token, reconnect presents the token from that stream’s last complete value
to reopen its original read.
Your own writes
A watch catches up when a commit changes what its query read, including a commit by the caller. Pass the mutation’sversion as seen to wait for an
answer that includes that write. See Retries and read-your-writes.
Head only
The head is watched live. A watch in another world or at a valid instant (client.in(version), client.at(instant)) answers once, for the state it
names. See Frames and trials.