I want to destroy the editor instance manually and then set it again when the component is updated.
I am using ReactJs but I am not using the react wrapper.
Whenever I try to call the destroy function I got the error that destroy is not a function.
const MyEditor = () => {
const [editor, setEditor] = useState([]);
useEffect(() => {
if (editor.length != 0) {
editor.destroy();
}
setEditor(
new EditorJS({
holder: "editor",
placeholder: "Insert your text here!",
tools: {
header: Header,
list: List,
quote: Quote,
checklist: Checklist,
code: Code,
table: Table,
image: {
class: ImageTool,
config: {
endpoints: {
byFile: "myFile",
byUrl: "myUrl"
}
}
}
},
data: {
blocks: myBlocks
}
})
);
}, [myData]);
Make sure you call destroy() on the editor instance. Try to debug editor variable, looks like it stores something different.
Although I got this when I try to debug the editor variable.
_t {isReady: Promise}
clear: 茠 ()
configuration: {holder: "editor", placeholder: "Insert your event details here!", tools: {鈥, data: {鈥, initialBlock: "paragraph", 鈥
destroy: 茠 ()
emit: 茠 (e, n)
focus: 茠 ()
isReady: Promise {
off: 茠 (e, n)
on: 茠 (e, n)
render: 茠 (e)
save: 茠 ()
__proto__: Object_
But it then gives me the same error that the destroy is not a function
Maybe editor is already destroyed?
No.
When I run the code it gives me 2 instances of the editor on the page.
So, I want the first instance to be destroyed
Ok we will test it.
if (editor.length != 0) {
editor.destroy();
}
Looks like editor is an Array. Try editor[0].destroy()
any update on this issue? I have the same problem, every time I try to destroy the editor instance, it keeps saying that the destroy is not a function.
you can use it inside isReady
editor.isReady
.then(() => {
// editor.destroy();
/** Do anything you need after editor initialization */
});
For anyone getting this error, editor can not be destroyed while it is loading!
any updates on this matter?
I have a TypeError when running destroy() on the editor instance.
Unhandled Runtime Error
TypeError: Cannot read property 'deactivate' of null