Draft-js: 'tex' example not working: Entity, cannot read property 'create' of undefined

Created on 24 Nov 2016  路  2Comments  路  Source: facebook/draft-js

I was testing the examples to create my own table editor, and as some issues' comments state it, I was looking at the TeX example. It runs well until I hit 'Insert new TeX'.

The following error is displayed:

app.js:59939 Uncaught TypeError: Cannot read property 'create' of undefined

This portion of code fails:

var entityKey = _draftJs.Entity.create('TOKEN', 'IMMUTABLE', { content: examples[nextFormula] });

Are there any changes in the Entity API?

To reproduce the issue, just clone the repo as stated in the Overview page, go to the tex example and do.

npm install
npm start

Those are the steps I did. I did not modify the repo code in any way.

The Entity API is not available and the tex example is not fully working.
The version I tested was 0.9.1 on Chrome.
npm -v: 3.8.3
node -v: v5.10.1

Thanks!

Most helpful comment

entity API has been changed in master branch.. creation of entity is moved to contentState.
you need to call contentState.createEntity
https://github.com/facebook/draft-js/blob/6d5c4e91ddf42d7fa3f6ef310f8afae6378b07d4/src/model/immutable/ContentState.js#L138

All 2 comments

entity API has been changed in master branch.. creation of entity is moved to contentState.
you need to call contentState.createEntity
https://github.com/facebook/draft-js/blob/6d5c4e91ddf42d7fa3f6ef310f8afae6378b07d4/src/model/immutable/ContentState.js#L138

Thanks for explaining @mzbac - that is correct, and we should really have examples for both the old and new API until we fully release the new API. Just opened an issue to update the examples - #816.

Hopefully this is clear now, and sorry about the confusion! We will be documenting things more clearly and carefully going forward.

Was this page helpful?
0 / 5 - 0 ratings