This is my component in it's current state.
class TextInput extends React.Component<TextInputProps, any> {
constructor(props) {
super(props);
this.state = { editorState: EditorState.createWithContent(ContentState.createFromText(props.content))};
this.onChange = this.onChange.bind(this);
}
onChange(editorState) {
const { setContent } = this.props;
this.setState({editorState});
const plainText = editorState.getCurrentContent().getPlainText();
setContent({ content: plainText });
}
render() {
return (
<TextEditor
editorState={this.state.editorState}
onChange={this.onChange}
/>
);
}
};
So basically I'm holding the content of the editor in my redux state while draft.js manages the rest inside the component. What I'm looking for is to be able to set the state (plain text content only) of the editor without using createWithContent. I haven't been able to find a state.set or similar in the docs.
Is replaceText the closest alternative? (https://draftjs.org/docs/api-reference-modifier.html#replacetext)