JsonFormsContext
The React Context that provides JSON Forms state throughout the component tree.Context Value
The context value is of typeJsonFormsStateContext:
Core state object containing:
data(any) - Current form dataschema(JsonSchema) - JSON Schemauischema(UISchemaElement) - UI Schemaerrors(ErrorObject[]) - Validation errorsadditionalErrors(ErrorObject[]) - Additional errorsvalidator(ValidateFunction) - Validation functionajv(Ajv) - Ajv instance
Registry of available renderers
Registry of available cell renderers
Configuration object
Registry of UI schemas for dynamic resolution
Whether the form is in read-only mode
Internationalization state:
locale(string) - Current localetranslate(Translator) - Translation functiontranslateError(ErrorTranslator) - Error translation function
Function to dispatch actions to update the core state
Accessing Context
Use theuseJsonForms hook to access the context:
JsonFormsStateProvider
Context provider component that manages JSON Forms state. Handles state initialization, updates, validation, and change notifications.Props
Initial state configuration containing:
core- Core state with data, schema, uischema, ajv, validationMode, additionalErrorsrenderers- Renderer registrycells- Cell renderer registryconfig- Configuration objectuischemas- UI schema registryreadonly- Read-only flagi18n- Internationalization state
Callback invoked when data or errors change. Debounced by 10ms to handle rapid updates.
Middleware function for intercepting and transforming actions before they reach the reducer.Signature:
Child components that will have access to the JSON Forms context
State Management
The provider manages state through reducers:- Core Reducer - Handles data updates, validation, and schema changes
- Config Reducer - Manages configuration updates
- i18n Reducer - Manages internationalization state
Change Detection
Changes are debounced by 10ms to handle edge cases like browser auto-fill that may trigger multiple rapid updates. This prevents data loss and infinite render loops.Example: Custom Provider Setup
Middleware
Middleware allows you to intercept and transform actions before they update the state.Default Middleware
The package exports adefaultMiddleware that simply passes actions through:
Custom Middleware Example
Middleware Use Cases
- Logging - Track all state changes for debugging
- Validation - Add custom validation logic
- Data transformation - Transform data before/after updates
- Side effects - Trigger external actions on specific changes
- Undo/Redo - Implement history tracking
- Optimistic updates - Handle async operations
Context HOC
withJsonFormsContext
Higher-order component that injects the JSON Forms context into a component.Example
useJsonForms hook is preferred over this HOC.
Internal State Types
JsonFormsCore
The core state shape:ValidationMode
Controls when and how validation errors are displayed:ValidateAndShow- Validate and show all errors immediatelyValidateAndHide- Validate but don’t show errors initiallyNoValidation- Disable validation