I am using tinymce editor in my project. The code is as follows.
<Editor
initialValue={selectedDocument.html_content}
init={{
plugins: 'link image code',
toolbar: 'undo redo | bold italic | alignleft aligncenter alignright | code',
height: 600
}}
onChange={this.handleEditorChange}
/>
To clear the editor i used the following code
clearEditorContent = () => {
let documentDetails = {...this.state.documentDetails};
documentDetails['html_content'] = '';
this.setState({documentDetails});
}
handleEditorChange = (e) => {
let htmlContent = e.target.getBody().innerHTML;
this.setDocumentDetails('html_content', htmlContent)
}
But this clearEditorContent method somehow triggers the handleEditorChangeMethod and again sets the html_content
(content is still there in the editor and so e.target.getBody().innerHTML sets html_content again).
Any idea on what is wrong here?
Also, is there any alternate approach to clear the editor content?