How Edit/Save works in ProseMirror?

Hi, maybe it’s a trivial question but I want to use ProseMirror editor on my website and I’m wondering how Edit/Save functionality works here. I mean that the user can create a post using this editor, but what should happen after clicking “Save” (or “Post”)? Which part of the editor should be saved to the database and what should happen after clicking “Edit”, i.e. how to go back to editor view from the information saved into database?

1 Like

Depending on what you want in your database, you can store state.doc.toJSON() or use DOMSerializer and then innerHTML to convert the document to HTML.


Also, if you’re using YJS and y-prosemirror (handy for offline editing, real-time collaboration, version history, etc) you can persist a ydoc binary using const ydocUpdate = Y.encodeStateAsUpdate(ydoc) and you can restore it using Y.applyUpdate(ydoc, ydocUpdate).