Skip to content

Middlewares

Middlewares are functions that wrap the form’s reactive store and observe (or mutate) every action that flows through it. They run on every state change and can be composed.

middlewares goes inside the config object in both paths.

GolemUI ships a few middlewares you can opt into:

MiddlewareWhat it does
loggerMiddlewareLogs each action and the resulting state to the console — handy during development.
devToolsMiddlewarePipes actions to the Redux DevTools extension for time-travel debugging.

Pass an array of middlewares inside the config object as the middlewares property. Below, every framework wires devToolsMiddleware.

import { devToolsMiddleware } from '@golemui/core';
import { gui } from '@golemui/gui-shared';
import { GuiForm } from '@golemui/gui-react';
const config = {
formDef: [gui.inputs.textInput('username')],
middlewares: [devToolsMiddleware()],
};
export function MyForm() {
return <GuiForm config={config} />;
}
import { devToolsMiddleware } from '@golemui/core';
import { GuiForm } from '@golemui/gui-react';
import formDef from './my-form.json';
const config = { formDef, middlewares: [devToolsMiddleware()] };
export function MyForm() {
return <GuiForm config={config} />;
}

See Extending GolemUI / Middlewares for the middleware contract and a worked example.