Skip to content

Instantly share code, notes, and snippets.

@tomcask
Created December 23, 2016 08:19
Show Gist options
  • Save tomcask/bafaff82502721edb564f0a0121ae021 to your computer and use it in GitHub Desktop.
Save tomcask/bafaff82502721edb564f0a0121ae021 to your computer and use it in GitHub Desktop.
Create draftjs blocks with images
const createBlocksWithImage = ()=>{
const url = "https://www.google.es/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png";
const entityKey = Entity.create( 'image', 'IMMUTABLE', { src: url } );
const charData = CharacterMetadata.create({ entity: entityKey })
const blockSpec = {
type : 'atomic',
text : ' ',
key: genKey(),
depth: 0,
characterList: List(Repeat(charData, 1))
}
let contentState = ContentState.createFromBlockArray([new ContentBlock(blockSpec)]);
return EditorState.createWithContent(contentState);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment