I can't save my diagram after making changes to the view ReactHooks

#Hello everyone!,
I am trying to save my diagram after making changes to the view, but it does not save me an error appears, can someone help me please

const openBpmnDiagram = async (diagram) => {
    const modeler = new BpmnModeler({
      container: bpmContainerRef.current,
      keyboard: {
        bindTo: window,
      },
      additionalModules: [customModule, customContextPadProvider],
      propertiesPanel: {
        parent: "#propview",
      },
    });

    try {
      await modeler.importXML(diagram);
      console.log('XML', diagram)
      const res = await modeler.saveXML({ format: true })
      setDiagram(res);
      const canvas = modeler.get("canvas");
      canvas.zoom("fit-viewport");
    } catch (err) {
      console.log(err);
    }
  };

img1

I’ve been trying other ways but it still doesn’t work for me

const exportDiagram = async (e) => {
    e.preventDefault()
    const modeler = new BpmnModeler({
      container: bpmContainerRef.current,
      keyboard: {
        bindTo: window,
      },
      additionalModules: [customModule, customContextPadProvider],
      propertiesPanel: {
        parent: "#propview",
      },
    });

    const { xml } = await modeler.saveXML();
    setDiagram(xml);

  }

I get this error
img1

Thanks for sharing the code snippets! The second one won’t work because there is no diagram imported before using saveXML. For the first one, what does your diagram look like? The error tells that import is not possible, probably because the diagram is undefined.

Are you able to share your setup inside a CodeSandbox?

Hello, thank you very much for your answer. @Niklas_Kiefer

Here is the code, it still doesn’t work for me :frowning:

funny-keller-2suhcx - CodeSandbox

Thanks for sharing! Your method openBpmnDiagram requires a parameter diagram. However your save button doesn’t provide one.

<button
  onClick={() => openBpmnDiagram()}
  className="ml-3 "
  color="primary">
    save
</button>

That’s why the import is failing, diagram is undefined.

** @Niklas_Kiefer Thanks for answering.

I pass him the diagram but it seems that he accepts me, it is empty and the diagram is not updated to save it.**

https://codesandbox.io/s/funny-keller-2suhcx?file=/src/App.js