O3 Framework / useDefineAppContext
useDefineAppContext<
T>(namespace,value?): (update) =>void
Defined in: packages/framework/esm-react-utils/src/useDefineAppContext.ts:43
This hook is used to register a namespace in the AppContext. The component that registers the namespace is responsible for updating the value associated with the namespace. The namespace will be automatically removed when the component using this hook is unmounted.
T extends object = object
The type of the value of the namespace
string
The name of the namespace in the application context. Note that the namespace must be unique among currently registered namespaces in the application context.
T
The value to associate with this namespace. Updating the value property will update the namespace value.
A function which can be used to update the state associated with the namespace
(
update):void
(state) => T
void
const { data: patient } = useSWR(`/ws/rest/v1/patient/${patientUuid}`, openmrsFetch);
useDefineAppContext<PatientContext>('patient', patient ?? null);
const { data: patient } = useSWR(`/ws/rest/v1/patient/${patientUuid}`, openmrsFetch);
const updatePatient = useDefineAppContext<PatientContext>('patient', patient ?? null);
updatePatient((patient) => {
patient.name = 'Hector';
return patient;
})
Note that the AppContext does not allow the storing of undefined values in a namespace. Use null
instead.