How can I clean an Editor after successfully handle onSubmit function? #2843
-
In my react app, I have created a component name RichTextEditor using lexical. Now I want to clean the Editor from a different component. No idea how to do it. I have checked for question regarding this clean. But it's not clear for me how to implement it. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You need access to the editor instance from your other component, by passing the editor.update(() => {
const root = $getRoot();
root.clear();
}); We provide an importabl plugin called To clear the editor, you can call |
Beta Was this translation helpful? Give feedback.
You need access to the editor instance from your other component, by passing the
MLCComposer
provider up to a common parent, but you can then do something like the below to clear the editor state:We provide an importabl plugin called
ClearEditorPlugin
which will also handle this use case for you.To clear the editor, you can call
editor.dispatchCommand(CLEAR_EDITOR_COMMAND)
from your other component.