declaring a property in constructor with typescript react

后端 未结 3 1333
北恋
北恋 2021-02-12 13:22

From the draft-js documention, one can (in vanilla React, with no typescript) setup the Draft-js environment thus, noticing that the onChange property can be declar

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-12 14:11

    You can use handleChange method like this :

    import * as React from 'react';
    import * as ReactDOM from 'react-dom';
    import { Editor, EditorState } from 'draft-js';
    
    interface MyEditorProps {
    }
    
    class MyEditor extends React.Component {
      constructor(props: MyEditorProps) {
        super(props);
    
        this.state = { editorState: EditorState.createEmpty() };
      }
      handleChange(e: EditorState) {
        this.setState({ editorState: e });
      }
      render() {
        return (
           this.handleChange(e)} />
        );
      }
    }
    
    ReactDOM.render(
      ,
      document.getElementById('editor'),
    );
    
    export { MyEditor }

提交回复
热议问题