Last active
June 11, 2019 19:54
-
-
Save NilsonLima/664337ada3f6086682133503e287f8bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // @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