Skip to content

Custom Middlewares

A middleware is a function that wraps the store’s dispatch pipeline. The signature is the standard Redux-style triple-function:

import * as Core from '@golemui/core';
export const myMiddleware: Core.Middleware<Core.State, Core.Action> =
(store) => (next) => (action) => {
console.log('Before:', action.type, store.getState());
const result = next(action);
console.log('After:', store.getState());
return result;
};

Pass it through the middlewares prop of the form component (this stays as a separate prop, not inside formConfig).

  • Logging. Log every action and resulting state — useful during development.
  • Persistence. Watch a subset of actions and persist the form state to localStorage.
  • Schema validation. Validate every state mutation against a JSON Schema and reject invalid changes.
  • Telemetry. Emit analytics events for specific user interactions.