O3 Framework / 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.
string
The UUID of the patient whose attachments should be fetched.
boolean
Whether to include attachments that are not associated with any encounter.
object
An object containing:
data: Array of attachment objects (empty array while loading)isLoading: Whether the initial fetch is in progressisValidating: Whether any request (initial or revalidation) is in progresserror: Any error that occurred during fetchingmutate: Function to trigger a revalidation of the datadata:
AttachmentResponse[]
error:
any
isLoading:
boolean
isValidating:
boolean
mutate:
KeyedMutator<FetchResponse<{results:AttachmentResponse[]; }>>
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} />;
}