0

Does anyone have an example to reflect the updates in an editor instance to another instance?

The docs for Lexical.js are very poor.

1 Answer 1

0

I got this working using a custom plugin, which I hate that I had to do:

      <Main>
        <LexicalComposer initialConfig={initialConfig}>
          <UpdateEditorPlugin
            jsonString={stateString}
          />
        </LexicalComposer>


        <LexicalComposer initialConfig={initialConfig}>
          <UpdateEditorPlugin
            jsonString={stateString}
          />
        </LexicalComposer>
      </Main>

Plugin:

export default function UpdateEditorPlugin({
  //@ts-ignore
  jsonString
}): JSX.Element | null {
  const [editor] = useLexicalComposerContext();

  useEffect(() => {
    editor.update(() => {
      const newState = editor.parseEditorState(jsonString);
      queueMicrotask(() => {
        editor.setEditorState(newState);
      });
    });

  }, [jsonString]);

  return null;
}

But the editor loses focus after each keystroke. If you work that one out, let me know. Plenty of people having issues with the editor stealing focus when updated, on the Lexical discord: https://lexical.dev/community

Hopefully this is a really bad way of doing it, which will spur someone on to give a better answer!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.