Count
Count the entities of one schema with useLensCount.
What it is
useLensCount asks the graph how many entities a schema has. It calls lens.count() with no criteria. Use it for a
total, and a rule for a derived value, as Schemas and LDKit describes.
Import
import { useLensCount, useSparqlOptions } from "@manta-eu/react/ldo-ui";
useSparqlOptions() takes no arguments and returns the LDKit Options for the connection set up by
SparqlOptionsProvider.
Example
import { useLensCount, useSparqlOptions } from "@manta-eu/react/ldo-ui";
import { YourSchema } from "./.ldkit/your-namespace";
export function YourTotal() {
const options = useSparqlOptions();
const { data } = useLensCount({ schema: YourSchema, options, queryKey: ["your-entities", "count"] });
return <p>{data ?? "…"}</p>;
}
Request
useLensCount({
schema, // S
options, // Options from useSparqlOptions()
queryKey, // readonly unknown[]
enabled, // boolean, optional, defaults to true
});
The parameter type is UseSparqlQueryOptions<S> with iri omitted. The hook passes no where and no max to
lens.count(), so the number is every entity of the schema.
Response
The hook returns TanStack Query’s UseQueryResult<number, Error>.
{
data: number | undefined;
error: Error | null;
status: "pending" | "error" | "success";
isPending: boolean;
isError: boolean;
isSuccess: boolean;
}
data is the count once the query succeeds. lens.count() resolves to that number.