In my project I have integrated the editor from react-draft-wysiwyg. Now I need to test the text editor by loading it with some text data. I tried to follow the documentation and my code currently looks like this:
import React, { Component } from 'react';
import { Editor } from 'react-draft-wysiwyg';
import 'react-draft-wysiwyg/dist/react-draft-wysiwyg.css';
import './textEditor.css';
import { convertFromRaw } from 'draft-js';
const content = {
"entityMap":{
},
"blocks":[
{
"key":"637gr",
"text":"Initialized from content state.",
"type":"unstyled",
"depth":0,
"inlineStyleRanges":[
],
"entityRanges":[
],
"data":{
}
}
]
};
export default class RichTextEditor extends Component {
constructor(props) {
super(props);
const contentState = convertFromRaw(content);
this.state = {
contentState,
}
}
onContentStateChange: Function = (contentState) => {
this.setState({
contentState,
});
};
render() {
const { contentState } = this.state;
return (
<div>
<Editor
editorClassName={"report-editor"}
editorState={this.props.editorState}
onEditorStateChange={this.props.onEditorStateChange}
onContentStateChange={this.props.onContentStateChange}
/>
</div>
)
}
}
I tried to follow the documentation but the json isn't loading. I tried to understand the workarounds but couldn't as I have never used DraftJS before. Can anyone help me with this?
onContentStateChange = Function = (contentState) => { ... }
before. It seems that you have a bunch of basic React related errors. Try taking a look at some of the many Draft.js codepens out there, such as codepen.io/Kiwka/pen/YNYvyG. – mzedeleronContentStateChange = Function = (contentState) => { ... }
it says right in the documentation. (under the section data conversion) – Proteeti Prova