Skip to content

Runtime Methods

setData and setMeta let you push state changes into a mounted form without re-initialising it. Use them to pre-fill fields after an async fetch, sync the form with external state, or toggle meta-driven behaviour at runtime.

Both methods replace their respective state objects entirely — there is no deep merge.

Each framework has its own mechanism for obtaining a handle to the form component instance:

import { useRef } from 'react';
import { GuiForm } from '@golemui/gui-react';
import type { FormComponentHandle } from '@golemui/react';
export function MyForm({ config }) {
const formRef = useRef<FormComponentHandle>(null);
return <GuiForm ref={formRef} config={config} />;
}

Replaces the form’s current data state. All field values are overwritten with the supplied object.

import { useRef } from 'react';
import { GuiForm } from '@golemui/gui-react';
import type { FormComponentHandle } from '@golemui/react';
export function MyForm({ config }) {
const formRef = useRef<FormComponentHandle>(null);
async function loadUser(userId: string) {
const user = await fetchUser(userId);
formRef.current?.setData({ name: user.name, email: user.email });
}
return (
<>
<button onClick={() => loadUser('42')}>Load user</button>
<GuiForm ref={formRef} config={config} />
</>
);
}

Replaces the form’s current meta state. Meta values are available inside the form definition for template interpolation ({{$meta.key}}) and conditions ($meta.key === true).

import { useRef } from 'react';
import { gui } from '@golemui/gui-shared';
import { GuiForm } from '@golemui/gui-react';
import type { FormComponentHandle } from '@golemui/react';
const formDef = [
gui.displays.alert('status-banner', {
text: 'Connection: {{$meta.status}}',
}),
];
const config = { formDef, meta: { status: 'offline' } };
export function MyForm() {
const formRef = useRef<FormComponentHandle>(null);
function goOnline() {
formRef.current?.setMeta({ status: 'online' });
}
return (
<>
<button onClick={goOnline}>Connect</button>
<GuiForm ref={formRef} config={config} />
</>
);
}
MethodSignatureDescription
setData(data: Record<string, any>) => voidReplaces the form’s data state. All field values are overwritten.
setMeta(meta: Record<string, any>) => voidReplaces the form’s meta state. Used in template interpolations and conditions.