React newbie here. I have a contenteditable
div which has dangerouslySetInnerHTML
as the child, since I need to format whatever the user enters,at runtime. On a particular span click inside the HTML, I want to setState
one of the variables of the containing component.
Can this be done?
If not, how should I change my structure ?
Here's the code:
updateText:function(){
var txt = $('#text_Box').text();
if(txt.indexOf('@Name') > -1)
{
txt = txt.replace('@Name','<span class=\'tagged\' contenteditable = \'false\' onclick=\'doSomething()\'>:Name</span>');
}
this.setState({userText:txt});
},
render:function(){
return <div className="inputDiv" contentEditable="true" type="text" className="form-control" id="text_Box" dangerouslySetInnerHTML={{__html:this.state.userText}} onInput = {this.updateText} />
}
the doSomething() method is what I'm taking about.