Skip to content

Instantly share code, notes, and snippets.

@NilsonLima
Last active June 11, 2019 19:54
Show Gist options
  • Save NilsonLima/664337ada3f6086682133503e287f8bb to your computer and use it in GitHub Desktop.
Save NilsonLima/664337ada3f6086682133503e287f8bb to your computer and use it in GitHub Desktop.
// @flow
import * as React from "react";
import { Editor, EditorState } from "draft-js";
type Props = {
onChangeText?: (text: string) => void
};
type State = {
editorState: EditorState
};
export default class CustomEditor extends React.Component<Props, State> {
static defaultProps = {
onChangeText: () => {}
};
state = { editorState: EditorState.createEmpty() };
onChange = (editorState: EditorState) => {
const { onChangeText } = this.props;
const text = editorState.getCurrentContent().getPlainText();
this.setState({ editorState }, () => {
if (onChangeText) onChangeText(text);
});
};
render() {
const { editorState } = this.state;
return <Editor editorState={editorState} onChange={this.onChange} />;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment