Skip to Content
Effetch Query
React

Read many queries

Read several queries in one component.

useQueries reads a list of queries whose length changes, such as one per selected item, and returns their results in the same order. Combine them with AsyncResult.all:

The examples import todos.ts from Getting started.

import * as  from "effect/reactivity/AsyncResult";

import {  } from "@monarcode/effetch-query/react";

import {  } from "./todos.js";

export function ({
  ,
}: {
  readonly : <number>;
}) {
  const  = .(
    (.(() => ({ : {  } }))),
  );

  return .()
    .(() => (
      <>
        {.(() => (
          < ={.}>{.}</>
        ))}
      </>
    ))
    .(() => <>Couldn't load them</>)
    .(() => <>Loading…</>);
}

Each query gets the mount policy as it joins the list, and a null entry reads Initial. A query listed twice is read once, and shows in both places. A tuple of queries gives a tuple of results, each typed by its query. The array keeps its identity while every result does, so it can be a dependency of useMemo.

Its options (UseQueriesOptions) take only paused (Pause screens you can't see). As with useQuery, a server render reads only the cache.