O3 Framework / useAppContext
useAppContext<
T>(namespace):undefined|Readonly<T>
Defined in: packages/framework/esm-react-utils/src/useAppContext.ts:30
This hook is used to access a namespace within the overall AppContext, so that a component can use any shared contextual values. A selector may be provided to further restrict the properties returned from the namespace.
T extends object = object
The type of the value stored in the namespace
string
The namespace to load properties from
undefined | Readonly<T>
The current value registered under namespace, or undefined when the namespace has not
yet been registered, was unregistered (e.g. the owning component unmounted), or is a blank string.
Consumers should handle the undefined case explicitly rather than defaulting to {}, since an
empty-object default can mask a genuinely missing namespace and hide bugs.
// load a full namespace
const patientContext = useAppContext<PatientContext>('patient');
// loads part of a namespace
const patientName = useAppContext<PatientContext, string | undefined>('patient', (state) => state.display);
useAppContext<
T,U>(namespace,selector):undefined|Readonly<U>
Defined in: packages/framework/esm-react-utils/src/useAppContext.ts:60
This hook is used to access a namespace within the overall AppContext, so that a component can use any shared contextual values. A selector may be provided to further restrict the properties returned from the namespace.
T extends object = object
The type of the value stored in the namespace
U = T
The return type of this hook which is mostly relevant when using a selector
string
The namespace to load properties from
(state) => Readonly<U>
An optional function which extracts the relevant part of the state
undefined | Readonly<U>
The selected value, or undefined when the namespace has not yet been registered, was
unregistered (e.g. the owning component unmounted), or is a blank string. Consumers should handle
the undefined case explicitly rather than defaulting to {}, since an empty-object default can
mask a genuinely missing namespace and hide bugs.
// load a full namespace
const patientContext = useAppContext<PatientContext>('patient');
// loads part of a namespace
const patientName = useAppContext<PatientContext, string | undefined>('patient', (state) => state.display);