Hello!
I’m currently trying to integrate version 1.7.3 of the Form.js editor into my React JS project.
My import looks like this:
import { FormEditor } from "@bpmn-io/form-js";
import "@bpmn-io/form-js/dist/assets/form-js.css";
import "@bpmn-io/form-js/dist/assets/form-js-editor.css";
My code looks like this:
const divRef = useRef<HTMLDivElement>(null);
const formEditor = useRef<FormEditor | null>(null);
const [error, setError] = useState<unknown>();
useEffect(() => {
const div = divRef.current;
if (!div) return;
formEditor.current = new FormEditor({ container: div });
return () => {
formEditor.current?.destroy();
formEditor.current = null;
};
}, []);
useEffect(() => {
const editor = formEditor.current;
if (editor) {
const handler = () => {
onChange(JSON.stringify(editor.getSchema()));
void onBlur();
};
editor.on("changed", handler);
return () => {
editor.off("changed", handler);
};
}
}, [onBlur, onChange]);
useEffect(() => {
const editor = formEditor.current;
if (editor && JSON.stringify(editor.getSchema()) !== value) {
editor
.importSchema(JSON.parse(value))
.then(() => {
onChange(JSON.stringify(editor.getSchema()));
void onBlur();
})
.catch(setError);
}
});
The integration works without any issues. The editor is displayed, and it can be interacted with. However, I’m encountering some peculiar display errors at times.
When I drag a component into the Components section, it disappears from the editor. However, the component doesn’t disappear from the schema. If I reload the editor, it reappears.
Could it possibly be related to my integration or to the rendering of React?