-
Notifications
You must be signed in to change notification settings - Fork 419
Labels
Milestone
Description
Description
Sometimes general modifications of JSON Forms behavior would be useful. For example to listen on update events and to modify errors and data before they are set.
Solution
Similar to the middleware concept in Redux, the JsonForms component could accept a middleware function.
Conceptually the API could look like this
const loggerMiddleware = (previousState, dispatch, action) => {
console.log('dispatching', action)
// here you could modify the action or dispatch multiple ones
const nextState = dispatch(previousState, action)
// here you could modify the resulting state
console.log('next state', nextState)
return nextState;
}On JSON Forms side this can be implemented by handling the core state via useState instead of useReducer.
Alternatives
- Instead of adding yet another parameter to the
JsonFormscomponent the middleware could also be provided by another context, similar to theJsonFormsStyleContext. - Instead of the
JsonFormscomponent only theJsonFormsStateProvidercomponent is enhanced. In that case the advanced use case of adding a middleware can be done by manually creating theJsonFormsStateProviderinstead of using theJsonFormscomponent.
Describe for which setup you like to have the improvement
Framework: [React]
Could also be implemented for Angular