Skip to Content

useOsdkMetadata

Fetch the runtime metadata of an object type, interface, or action, such as display names and property descriptions.

import { useOsdkMetadata } from "@osdk/react";

function useOsdkMetadata<T extends ObjectOrInterfaceDefinition | ActionDefinition<any>>(
  type: T,
): UseOsdkMetadataResult<T>;

Calls client.fetchMetadata(type) and returns the result. The metadata type follows the definition you pass: ObjectMetadata for an object type, InterfaceMetadata for an interface, and ActionMetadata for an action. The result is held in component state, not in the ObservableClient cache, and is not fetched again if type changes. The client caches Ontology metadata, so repeated calls for the same type do not repeat the network request.

Returns

FieldTypeDescription
loadingbooleantrue until the request settles.
metadataObjectMetadata | InterfaceMetadata | ActionMetadata | undefinedThe metadata, once loaded.
errorstring | undefinedThe error message if the request failed.

Example

src/EmployeeHeading.tsx
import { Employee } from "@my-app/sdk";
import { useOsdkMetadata } from "@osdk/react";

export function EmployeeHeading() {
  const { metadata, loading, error } = useOsdkMetadata(Employee);

  return (
    <header aria-busy={loading}>
      {error && <p role="alert">{error}</p>}
      <h1>{metadata?.pluralDisplayName ?? "Employees"}</h1>
      <p>{metadata?.description}</p>
    </header>
  );
}

See also

On this page