const insertText = (text: string) => {
let contentState = editorState.getCurrentContent();
const selectionState = editorState.getSelection();
const contentStateWithEntity = contentState.createEntity(
'MY_ENTITY_TYPE',
'IMMUTABLE'
);
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
contentState = Modifier.insertText(contentState, selectionState, text);
let newState = EditorState.push(
editorState,
contentState,
'insert-characters'
);
setEditorState(newState);
};