draft.js contentState.createEntity is not a function

1.1k views Asked by At

I copied the example of the draft.js editor and run it. This is an example from the official repository. https://github.com/facebook/draft-js/blob/master/examples/draft-0-10-0/link/link.html But when you click on the button

<button onMouseDown={this.confirmLink}> Confirm</button>

enter image description here

The function _confirmLink fails:

Uncaught TypeError: contentState.createEntity is not a function


  _confirmLink(e) {
      e.preventDefault();
      const {editorState, urlValue} = this.state;
      const contentState = editorState.getCurrentContent();
      console.log('contentState->', contentState) 
      const contentStateWithEntity = contentState.createEntity('LINK', 'MUTABLE', {url: urlValue});

Draft.js can not create an entity. console.log('contentState->', contentState) outputs to the console:

enter image description here

What could be the problem in this case?

0

There are 0 answers