Skip to content

Best practices for saving the content in a database #1840

Answered by zurfyx
charklewis asked this question in Q&A
Discussion options

You must be logged in to vote

JSON.stringify(editorState) and editor.setEditorState(editor.parseEditorState(editorStateJSON))

You may want to check how file import/export works! https://github.com/facebook/lexical/blob/main/packages/lexical-file/src/fileImportExport.js

That said, and one of the reasons why we have a ⚠️ on the main README is that we're actively working on a versioning system, especially oriented towards custom app nodes.

Alternatively, you can build your own format based on the tree structure.

editor.getEditorState().read(() => {
  $getRoot() // iterate from here and build your own JSON or whatever format you prefer
});

The last works best when you already have documents in certain format on the datab…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@charklewis
Comment options

@charklewis
Comment options

@zurfyx
Comment options

zurfyx Apr 18, 2022
Collaborator

@mrkchang
Comment options

Answer selected by thegreatercurve
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants