Respond to the newbie here. I have a div contenteditablethat has dangerouslySetInnerHTMLas a child, since I need to format everything that the user types at runtime. In a certain period of time, click inside the HTML, I want setStateone of the variables of the containing component.
Can this be done?
If not, how can I change my structure?
Here is 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} />
}
doSomething () method is what I accept.
source
share