openmrs-esm-core

O3 Framework / useAttachments

Function: useAttachments()

useAttachments(patientUuid, includeEncounterless): object

Defined in: packages/framework/esm-react-utils/src/useAttachments.ts:32

A React hook that fetches attachments for a patient using SWR for caching and automatic revalidation.

Parameters

patientUuid

string

The UUID of the patient whose attachments should be fetched.

includeEncounterless

boolean

Whether to include attachments that are not associated with any encounter.

Returns

object

An object containing:

data

data: AttachmentResponse[]

error

error: any

isLoading

isLoading: boolean

isValidating

isValidating: boolean

mutate

mutate: KeyedMutator<FetchResponse<{ results: AttachmentResponse[]; }>>

Example

import { useAttachments } from '@openmrs/esm-framework';
function PatientAttachments({ patientUuid }) {
  const { data, isLoading, error } = useAttachments(patientUuid, true);
  if (isLoading) return <span>Loading...</span>;
  if (error) return <span>Error loading attachments</span>;
  return <AttachmentList attachments={data} />;
}