Draft-js: How to append text to the end

Created on 24 Feb 2016  路  3Comments  路  Source: facebook/draft-js

  _insertText() {
    const editorState = this.state.editorState;
    const selection = editorState.getSelection();
    const contentState = editorState.getCurrentContent();
    const ncs = Modifier.insertText(contentState, selection, "wefoiwjoefjwoiefjoiwjefio");
    const es = EditorState.push(editorState, ncs, 'insert-fragment');
    this.setState(es);
  }

With above codes, i can't get the wef.... to be append to the end. I have work on this problem for hours, but still can't found the solution. The above code is written according to Tex sample.

Most helpful comment

I found the solution.

My init method is

  getInitialState() {
    return {
      editorState: EditorState.createEmpty()
    };
  },

So when i want to update editorState i need to call this.setState({editorState: es}), not this.setState(es). Really love this framework, thank you.

All 3 comments

It's not a bug.

I found the solution.

My init method is

  getInitialState() {
    return {
      editorState: EditorState.createEmpty()
    };
  },

So when i want to update editorState i need to call this.setState({editorState: es}), not this.setState(es). Really love this framework, thank you.

how to append to the end?

Was this page helpful?
0 / 5 - 0 ratings