I have this class. In all functions, this equals null except render() in Idea class. I tried to repeat solution from React.js: onChange event for contentEditable
class Idea extends React.Component {
render() {
return (
<div id="root"
onInput={this.emitChange}
onBlur={this.emitChange}
contentEditable
dangerouslySetInnerHTML={{__html: this.props.html}}>
</div>
);
}
shouldComponentUpdate(nextProps) {
return nextProps.html !== ReactDOM.findDOMNode(this).innerHTML;
}
componentDidUpdate() {
if (this.props.html !== ReactDOM.findDOMNode(this).innerHTML) {
ReactDOM.findDOMNode(this).innerHTML = this.props.html;
}
}
emitChange() {
var html = ReactDOM.findDOMNode(this).innerHTML;
if (this.props.onChange && html !== this.lastHtml) {
this.props.onChange({
target: {
value: html
}
});
}
this.lastHtml = html;
}
}
Map class:
class Map extends React.Component {
render() {
var handleChange = function (event) {
this.setState({html: event.target.value});
}.bind(this);
return (
<div>
<Header/>
<div id="map">
{this.props.map.root && (
<Idea html={this.props.map.root.title} idea={this.props.map.root} onChange={handleChange}/>
)}
</div>
</div>
);
}
}
I don't understand why this is always null. Can you help me? Thanks