React API Reference
useInterpreterStore
This React hook creates an interpreter store.
Reference
useInterpreterStore(builder, schema, options?)
Use the useInterpreterStore
function to create an interpreter store.
import { useInterpreterStore } from "@coltorapps/builder-react";
import { formBuilder } from "./form-builder";
const formSchema = {
entities: {
"51324b32-adc3-4d17-a90e-66b5453935bd": {
type: "textField",
attributes: {
label: "First name",
},
},
},
root: ["51324b32-adc3-4d17-a90e-66b5453935bd"],
};
export function App() {
const interpreterStore = useInterpreterStore(formBuilder, formSchema);
}
In the example above, we've hardcoded the schema, but typically, you would fetch it from some data source, for instance.
Parameters
useInterpreterStore
accepts three parameters:
Parameter | Type | Description |
---|---|---|
builder | object | The builder definition. |
schema | object | The schema that was built using the provided builder definition. |
options | object optional | An optional partial object with initialization options. |
You should know!
Ensure that the provided builder
and schema
parameters remain stable or are memoized. The interpreter store will be recreated if these references change, leading to data loss.
Options
The options
parameter properties:
Property | Type | Description |
---|---|---|
initialData | object optional | The optional partial initial data of the interpreter store. |
initialEntitiesValuesWithDefaults | boolean optional | A flag to enable or disable the automatic setting of default values. Defaults to true . |
Returns
The useInterpreterStore
function essentially creates and returns an interpreter store.