Manta Developers
GitHub
Menu

Read by IRI

Read a known set of entities with useEntitiesByIris.

What it is

useEntitiesByIris reads entities you already have IRIs for. It returns one entry per IRI, in the same order. Lookups made in the same render share one query per schema, up to 100 IRIs.

useEntity({ schema, iri, enabled? }) reads a single IRI through that same batcher. Prefer either hook over useLensFindByIri in list rows. The comparison is on Schemas and LDKit.

Import

import { isPresent } from "@manta-eu/lib/present";
import { useEntitiesByIris } from "@manta-eu/react/ldo-ui";

The hook calls useSparqlOptions() itself. Call it inside a SparqlOptionsProvider.

Example

import { isPresent } from "@manta-eu/lib/present";
import { useEntitiesByIris } from "@manta-eu/react/ldo-ui";
import { AccountSchema } from "./.ldkit/your-namespace";

export function Accounts({ accountIris }: { accountIris: readonly string[] }) {
  const { data = [] } = useEntitiesByIris({ schema: AccountSchema, iris: accountIris });
  const accounts = data.filter(isPresent);
  return (
    <ul>
      {accounts.map((account) => (
        <li key={account.$id}>{account.name}</li>
      ))}
    </ul>
  );
}

Request

useEntitiesByIris({
  schema, // S
  iris, // readonly string[]
  enabled, // boolean, optional, defaults to true
});

The query stays off when enabled is false, and when no entry in iris is an absolute IRI.

Response

The hook returns TanStack Query’s UseQueryResult<(SchemaInterface<S> | undefined)[], Error>.

{
  data: (SchemaInterface<S> | undefined)[] | undefined;
  error: Error | null;
  status: "pending" | "error" | "success";
  isPending: boolean;
  isError: boolean;
  isSuccess: boolean;
}

data lines up with iris. An entry is the entity ($id and the schema’s properties) or undefined when that IRI is not in the graph, or is not an absolute IRI. Filter those out before you render.