Last active
August 29, 2015 13:57
-
-
Save girishso/9876306 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @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