5

I'm building a rich text editor for a question and answer site.

As far as I know Lexical lets us get output data to JSON, JSON string, HTML, Markdown and others.

Based on the recommended best practices, what data should I save to a MySQL or MongoDB database?

This is a new site.

R.M. Reza
  • 725
  • 1
  • 8
  • 20
  • 1
    The reason Lexical has options is because you have options. "Best practices" are best in different situations. That aside, please don't ask for recommendations (opinion-based question) on StackOverflow; take a moment to read [ask]. – code May 29 '22 at 01:45
  • @code I have no specific conditions. Thank you for reminding. – R.M. Reza May 29 '22 at 01:51
  • If I may suggest, you might consider JSON, as it's not very complicated to work with and is easy to convert back. – code May 29 '22 at 03:50
  • Thanks for the suggest. JSON (type string) or JSON (type JSON) on MySQL? https://dev.mysql.com/doc/refman/8.0/en/json.html – R.M. Reza May 29 '22 at 04:06
  • 1
    Either, I guess. Probably JSON string so it's easier to store in the DB? – code May 29 '22 at 19:11
  • @code If we keep the lexical JSON Node, what if we switch to a different editor one day? – R.M. Reza May 08 '23 at 03:22
  • Then you would do HTML? – code May 08 '23 at 03:57

1 Answers1

0

It looks like it is recommended by Lexical to store a JSON string for the Lexical editor state

// Handler to store content
const onSubmit = () => {
  await saveContent(JSON.stringify(editor.getEditorState()));
}

https://lexical.dev/docs/concepts/editor-state

Then you can serialize/deserialized as described here: https://lexical.dev/docs/concepts/serialization#lexical---json

dgeorg
  • 26
  • 3
  • "... recommended by Lexical to store a JSON ...", Is there a sentence in the documentation that states this? Can you provide the link. – R.M. Reza May 08 '23 at 03:23
  • @R.M.Reza, dgeorg said "It looks like", not "they say" nor "they recommend". It is, in fact, shown as an example in the Lexical official documentation. Just recommend modifying the sentence to prevent confusion. Hope you have a good time coding :) – KBeDev Aug 12 '23 at 01:38