With the Lexical text editor framework, what's the easiest way to initialize the editor in React with a default text string?
I could, for instance, create an instance, manually save the JSON state, and then copy that JSON blob to my code, to set as initialEditorState
to PlainTextPlugin
, but this seems like I have to be missing something.
Thanks
The way to achieve it found in lexical codebase is like so
but I prefer to use stringified editorState then parse it to editorState by parseEditorState function owned by instance.
Here is another problem I'm confused which also seems I have to be missed something.
ParseEditorState is a function only used for instance, but I can't use useLexicalComposerContext under the init component which will return LexicalComposer(unexpected error will cause), so I need to write an extra plugin to achieve it. Something like that:
It seems not a good way to write, is there a better way to do it?