useMatchSubject
A hook that lets you get a list of Linked Data Objects for subjects matching the provided parameters.
import { useMatchSubject, useResource } from "@ldo/solid-react";
import React, { FunctionComponent } from "react";
import { ProfileShapeType } from "./.ldo/Profile.shapeType";
const Component: FunctionComponent = () => {
const resource = useResource("https://example.com/data");
// Gets all subjects in the database that have a type "Person"
const profiles = useMatchSubject(
ProfileShapeType,
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
"http://xmlns.com/foaf/0.1/Person",
null,
);
if (resource?.isLoading()) return <p>Loading...</p>;
return (
<div>
{profiles.map((profile) => (
<p key={profile["@id"]}>Name: {profile?.name}</p>
))}
</div>
);
};
Parameters
ShapeType: ShapeType
- The ShapeType dictating the shape of the Linked Data Objectpredicate: string | PredicateNode | null
- The predicate to matchobject: string | ObjectNode | null
- The object to matchgraph: string | GraphNode | null
- The graph to matchoptions?: UseMatchSubjectOptions
- Optional configuration
Returns
A list of linked data objects corresponding to the given matched items.