Skip to content

React middleware support #1670

@sdirix

Description

@sdirix

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 JsonForms component the middleware could also be provided by another context, similar to the JsonFormsStyleContext.
  • Instead of the JsonForms component only the JsonFormsStateProvider component is enhanced. In that case the advanced use case of adding a middleware can be done by manually creating the JsonFormsStateProvider instead of using the JsonForms component.

Describe for which setup you like to have the improvement
Framework: [React]

Could also be implemented for Angular

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions