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 retrieve it from a database, for instance.

Parameters

useInterpreterStore accepts three parameters:

ParameterTypeDescription
builderobjectThe builder definition.
schemaobjectThe schema that was built using the provided builder definition.
optionsobject optionalAn optional partial object with initialization options.

The options parameter properties:

PropertyTypeDescription
initialDataobject optionalThe optional partial initial data of the interpreter store.
eventsobject optionalAn optional partial object with events callbacks.

Returns

The useInterpreterStore function essentially creates and returns an interpreter store.

Events Callbacks

Each event emitted by the builder store is available as a callback within the events key of the options parameter. Every callback receives a specific payload based on the event.

CallbackDescription
onEntityValueUpdatedAn entity's value was updated.
onEntityErrorUpdatedAn entity's validation error was updated.
onEntityUnprocessableAn entity was marked as unprocessable.
onEntityProcessableAn entity was marked as processable.
onDataSetThe data was manually set.
Previous
<BuilderEntityAttributes />