useLinks
Load the objects linked from one or more source objects through a named link.
import { useLinks } from "@osdk/react";
function useLinks<T extends ObjectOrInterfaceDefinition, L extends LinkNames<T>>(
objects: Osdk.Instance<T> | Array<Osdk.Instance<T>> | undefined,
linkName: L,
options?: UseLinksOptions<LinkedType<T, L>>,
): UseLinksResult<LinkedType<T, L>>;Follows linkName from each source object and returns the linked objects as one list. Pass undefined while the source object is still loading; on the first render links is undefined, and once the hook subscribes it returns links: [] with isLoading: false until the source arrives.
Options
Prop
Type
Returns
Prop
Type
Example
import { Employee } from "@my-app/sdk";
import { useLinks, useOsdkObject } from "@osdk/react";
export function DirectReports({ employeeId }: { employeeId: number }) {
const { object: employee } = useOsdkObject(Employee, employeeId);
const { links: reports, isLoading, error } = useLinks(employee, "reports", {
orderBy: { fullName: "asc" },
});
return (
<section aria-busy={isLoading}>
{error && <p role="alert">{error.message}</p>}
<ul>
{reports?.map((report) => (
<li key={report.$primaryKey}>{report.fullName}</li>
))}
</ul>
</section>
);
}