Skip to content

Instantly share code, notes, and snippets.

@girishso
Last active August 29, 2015 13:57
Show Gist options
  • Save girishso/9876306 to your computer and use it in GitHub Desktop.
Save girishso/9876306 to your computer and use it in GitHub Desktop.
/** @jsx React.DOM */
var App = React.createClass({displayName: 'App',
getInitialState: function(){
return {html: "this is <em>an</em> <strong>example</strong>"};
},
render: function(){
var handleChange = function(event){
this.setState({html: event.target.value});
}.bind(this);
return (ContentEditable( {html:this.state.html, onChange:handleChange} ));
}
});
var ContentEditable = React.createClass({displayName: 'ContentEditable',
render: function(){
return React.DOM.div(
{onInput:this.emitChange,
onBlur:this.emitChange,
contentEditable:true,
dangerouslySetInnerHTML:{__html: this.props.html}});
},
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;
}
});
React.renderComponent(App(null ), document.body);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment