Find entities
Read the entities of one schema with useLensFind.
What it is
useLensFind reads the entities of one LDKit schema. It calls lens.find() with no search criteria, through the SPARQL
connection the Manta providers set up.
Give the schema every property the list renders, including a nested schema under "@schema" when a row shows a related
entity, and read the list with one useLensFind. The rest of that guidance is on
Schemas and LDKit.
Import
import { useLensFind, useSparqlOptions } from "@manta-eu/react/ldo-ui";
useSparqlOptions() takes no arguments and returns the LDKit Options for that connection. It throws unless the
component is inside a SparqlOptionsProvider (which EmbeddedChatProviders sets up).
Example
import { useLensFind, useSparqlOptions } from "@manta-eu/react/ldo-ui";
import { YourSchema } from "./.ldkit/your-namespace";
export function YourList() {
const options = useSparqlOptions();
const { data = [] } = useLensFind({ schema: YourSchema, options, queryKey: ["your-entities"] });
return (
<ul>
{data.map((entity) => (
<li key={entity.$id}>{entity.name}</li>
))}
</ul>
);
}
Request
useLensFind({
schema, // S
options, // Options from useSparqlOptions()
queryKey, // readonly unknown[]
enabled, // boolean, optional, defaults to true
});
The parameter type is UseSparqlQueryOptions<S>, which also has an optional iri. This hook calls lens.find() with
no arguments. useLensFindByIri requires iri and returns UseQueryResult<LensEntity<S> | null, Error>.
Response
The hook returns TanStack Query’s UseQueryResult<LensEntity<S>[], Error>.
type LensFindResult = {
data: Array<LensEntity<S>> | undefined;
error: Error | null;
status: "pending" | "error" | "success";
isPending: boolean;
isError: boolean;
isSuccess: boolean;
};
data is the entity array once the query succeeds. Each entity has $id and the properties of the schema. find()
with no take returns at most 1000 entities. For more, use createTypedLens
with take and skip.