-
Couldn't find a single place with a working example or even an idea of the proper way to get the editor cleared up from outside of it. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 14 replies
-
You might be able to achieve the result you want by adding a Failing that, any of the approaches in this comment should work. Make a code sandbox or update your question with a code sample if you need help getting that to work. Here’s a working example of cleaning up the editor from outside of it. Replace the value prop in the child component with imperative handles if you want it to be event-driven rather than data-driven. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
so my final solution for now on how to both reset or set a value externally: export const emptyValue = [{ type: "p", children: [{ text: "" }] }];
const ApiProvider = forwardRef<Api>((props, ref) => {
const state = useEditorState();
useEffect(() => {
if (!ref) {
return;
}
if (typeof ref === "function") {
} else {
ref.current = {
setValue: (value = emptyValue) => {
state.children = value;
state.onChange();
},
};
}
}, [ref]);
return null;
}); then you render usage: editorApi.current.setValue([{ type: "p", children: [{ text: "hello" }] }]);
// or for reset
editorApi.current.setValue(); |
Beta Was this translation helpful? Give feedback.
-
Solved by #2465. |
Beta Was this translation helpful? Give feedback.
Solved by #2465.