addCTABox = (boxTitle, boxText, buttonText, url, ctaTargetLinkOption) => {
const { editorState, onChange } = this.props;
const { currentEntity } = this.state;
let selection = editorState.getSelection();
if (currentEntity) {
console.log(editorState, 'editorState');
const entityRange = getEntityRange(editorState, currentEntity);
console.log(entityRange, 'entityRangeeeee');
selection = selection.merge({
anchorOffset: entityRange.start,
focusOffset: entityRange.end,
});
}
const contentState = editorState.getCurrentContent();
const contentStateWithEntity = contentState.createEntity(
'CTA_BOX',
'MUTABLE',
{
ctaTitle: boxTitle,
ctaText: boxText,
ctaButtonText: buttonText,
url,
targetOption: ctaTargetLinkOption,
},
);
console.log(contentStateWithEntity, 'contentStateWithEntity');
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
let newEditorState = EditorState.push(
editorState,
{ currentContent: contentStateWithEntity },
'insert-characters',
);
newEditorState = AtomicBlockUtils.insertAtomicBlock(
newEditorState,
entityKey,
`${buttonText}`,
);
onChange(newEditorState);
this.doCollapse();
};
Here is the error in the browser console`

Which versions of Draft.js, and which browser / OS are affected by this issue? Did this work in previous versions of Draft.js?
version 0.10.5
Hey @norayr93, how did you solve this?
@bsotodo I think instead of:
let newEditorState = EditorState.push(
editorState,
{ currentContent: contentStateWithEntity },
'insert-characters',
);
you can do:
let newEditorState = EditorState.push(
editorState,
contentStateWithEntity,
'insert-characters',
);
and that should remove the error.
Just ran into this issue as well. Should the documentation be updated for adding an entity? I hit this bc of using the code snippet for link entities from the advanced topics: entities page
Just ran into same, also because of bad snippet on advanced topics: entities page
Most helpful comment
@bsotodo I think instead of:
you can do:
and that should remove the error.