API reference · generated from source
Function: fetchQueryNode()#
function fetchQueryNode<TState, TArgs>(source, ...options): QueryNode<TArgs, TState>;Defined in: retree-query/src/fetchQueryNode.ts:180
Create a QueryNode driven by a plain async function.
Type Parameters#
| Type Parameter | Default type |
|---|---|
TState | - |
TArgs | Record<string, never> |
Parameters#
| Parameter | Type | Description |
|---|---|---|
source | (args) => Promise<TState> | Async function producing a query value for the given args. |
...options | FetchQueryNodeOptionsArgs<TArgs, TState> | Query arguments, polling interval, and node options — or "skip" to start disabled. |
Returns#
QueryNode<TArgs, TState>
A query node subscribed to the fetch source.
Remarks#
This is the smallest possible backend adapter: one-shot (or polled) fetches
flow through the same status machine, args lifecycle, reconciliation, and
optimistic-update machinery as realtime backends. Subscription lifecycle
follows Retree observation — the fetch runs when the node gains its first
observer, and retry() re-fetches after an error.
Example#
const weather = Retree.root(
fetchQueryNode(
(args: { city: string }) => fetchWeather(args.city),
{ args: { city: "Seattle" }, refetchInterval: 60_000 }
)
);