Skip to content

Instantly share code, notes, and snippets.

@Katerina198b
Created May 2, 2020 11:26
Show Gist options
  • Save Katerina198b/f43bcb702db99bef40ddb1be481bc6df to your computer and use it in GitHub Desktop.
Save Katerina198b/f43bcb702db99bef40ddb1be481bc6df to your computer and use it in GitHub Desktop.
function addEmptyBlock(editorState) {
const newBlock = new ContentBlock({
key: genKey(),
type: 'unstyled',
text: '',
characterList: List(),
});
const contentState = editorState.getCurrentContent();
const newBlockMap = contentState.getBlockMap().set(newBlock.key, newBlock);
const editorWithBlock = EditorState.push(
editorState,
ContentState.createFromBlockArray(newBlockMap.toArray())
);
return EditorState.moveFocusToEnd(editorWithBlock);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment