I have this data in my redux store which I want to render in my react component .
{
"entityMap":{
"0":{
"type":"LINK",
"mutability":"MUTABLE",
"data":{"url":"www.google.co.in"}
}
},
"blocks":[
{
"key":"9k5h7",
"text":"this is the link",
"type":"unstyled",
"depth":0,
"inlineStyleRanges":[],
"entityRanges":[
{
"offset":12,
"length":4,
"key":0
}
],
"data":{}
}
]
}
I succesfully managed to create a link type with draft editor and was able to store it in database and while rendering it I am getting the entire text except for the link . I have this link information in my redux i.e the "entity map" and also the "entityRanges" inside "blocks" which tells on which offset the link starts and what is the length . for eg, here in my case it is "link" in "this is the link" .
Here is the code which i used to render the above json from my redux :
render(){
return(
<div>
{
var nn = abovejsonfromreduxstore;
var editorState = EditorState.createWithContent(convertFromRaw(JSON.parse(nn)));
return (
<div>
<pre>
<Editor
editorState={editorState}
readOnly
/>
</pre>
</div>
</div>
}
</div>
);
}
How to modify this rendering method so that it renders the link entity too ?
You should specify draft.js decorator this way:
Pass the
findLinkEntities
function tostrategy
property andLink
react component tocomponent
property:After that pass this decorator to
createWithContent
method:Check working example in the hidden snippet below: