Skip to content

Instantly share code, notes, and snippets.

@r2dev
Last active January 8, 2016 12:06
Show Gist options
  • Select an option

  • Save r2dev/36c96c07bdae7a7b9bed to your computer and use it in GitHub Desktop.

Select an option

Save r2dev/36c96c07bdae7a7b9bed to your computer and use it in GitHub Desktop.
Fail of the day i guess
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>form</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.5/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.5/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<div id="content"></div>
<script type="text/babel">
var FormControl = React.createClass({
getInitialState: function() {
return {inputFromUser: 'Hello'};
},
handleFormChange: function(inputValue) {
this.setState({inputFromUser: inputValue});
},
render: function() {
return (
<div>
<RealForm onFormChange={this.handleFormChange}/>
<DisplayPart text={this.state.inputFromUser} />
</div>
);
}
});
var RealForm = React.createClass({
getInitialState: function() {
return {value: ''};
},
handleChange: function(event) {
this.props.onFormChange(event.target.value);
this.setState({value: event.target.value});
},
render: function() {
return (
<input type="text" value={this.state.value} onChange={this.handleChange} />
);
}
});
var DisplayPart = React.createClass({
render: function() {
return (
<div>
{this.props.text}
</div>
);
}
});
ReactDOM.render(<FormControl />, document.getElementById("content"));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment