Draft-js-plugins: WARNING: DraftEntity.get will be deprecated soon!

Created on 8 Mar 2017  路  3Comments  路  Source: draft-js-plugins/draft-js-plugins

How about if DraftEntity.get is deprecated?

I get a warging with the latest draft-js.

WARNING: DraftEntity.get will be deprecated soon!
Please use "contentState.getEntity" instead.

If so, it seems impossible to get a Entify in blockRendererFn.
How to handle it?

Most helpful comment

Today I merged a PR upgrading to the latest Draft.js version including the API update. This will be available in Beta10 馃檶

All 3 comments

The blockRendererFn only receives a block as a parameter and returns a component. You should not need the Entity in blockRendererFn. If you need data in your block in order to render something specific, don't rely on the Entity but use Modifier.setBlockData that you can access with block.getData() instead (data in the block instead of being in the entity).

If you want to access an Entity, you have to be in the rendered component returned by blockRendererFn where contentState will be passed as a prop.

You can access your Entity by:

const entity = contentState.getEntity(block.getEntityAt(0))

See https://draftjs.org/docs/advanced-topics-block-components.html

@jebarjonet Thanks for the recommendation.

I see some Entity.get in draft-js-plugins, so I want to know how draft-js-plugins will handle this.

Today I merged a PR upgrading to the latest Draft.js version including the API update. This will be available in Beta10 馃檶

Was this page helpful?
0 / 5 - 0 ratings

Related issues

paglias picture paglias  路  4Comments

GaborLeskoFlach picture GaborLeskoFlach  路  3Comments

nikgraf picture nikgraf  路  3Comments

svnm picture svnm  路  3Comments

sessionboy picture sessionboy  路  3Comments