Created
December 23, 2016 08:19
-
-
Save tomcask/bafaff82502721edb564f0a0121ae021 to your computer and use it in GitHub Desktop.
Create draftjs blocks with images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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