So, I created a component to include content editing components in my application. I copied this from some kind of essence, I believe, and then edited what I need.
The code is below. When I edit it, it launches the parent updates just fine, but when I try to set props.html in the parent, it is not reflected in the user interface. NEXT, console.log shows that this.props.html is equal to the empty string, but the user interface does not update and supports the text that was originally there.
I donβt understand how this is possible ... dangerouslySetInnerHtml = {__html: ''} has to make the user interface display an empty string ... it looks like it should be impossible to show old text for it.
var React = require('react'); var ContentEditable = React.createClass({ render: function(){ //TODO: find where html=undefined and fix it! So I can remove this? Maybe I should keep this safety. var html = this.props.html || ''; console.log('content editable render, html: ', this.props.html); return <div id="contenteditable" onInput={this.emitChange} onBlur={this.emitChange} contentEditable dangerouslySetInnerHTML={{__html: html}}></div>; }, shouldComponentUpdate: function(nextProps){ return nextProps.html !== this.getDOMNode().innerHTML; }, emitChange: function(){ var html = this.getDOMNode().innerHTML; if (this.props.onChange && html !== this.lastHtml) { this.props.onChange({ target: { value: html } }); } this.lastHtml = html; } }); module.exports = ContentEditable;
(A bit of background, I'm trying to clear my input after sending it to save. Cleaning does not work, hence this question.)
source share