I don't get the updated diagram when saving (React Hooks)

Hello everyone,

I have a problem, when I click the save button, the updated diagram is not saved.

  const [diagram, setDiagram] = useState(emptyBpmn);

try {
      await modeler.importXML(diagram);
      const { xml } = await modeler.saveXML();
      setDiagram(xml);
      const canvas = modeler.get("canvas");
      canvas.zoom("fit-viewport");
    } catch (err) {
      console.log(err);
    }

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

This is because each time you click the save button, a new instance of Modeler is created which imports the initial diagram. I re-arranged and simplified your codesandbox so that it imports BPMN only once and then only displayed saved XML:

1 Like

Thank you very much, the code is very complete!