Skip to content

Instantly share code, notes, and snippets.

Created July 22, 2016 08:44
Show Gist options
  • Save anonymous/560d06d27f0dbfcb1abc1e6348162250 to your computer and use it in GitHub Desktop.
Save anonymous/560d06d27f0dbfcb1abc1e6348162250 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/xihegu
<!DOCTYPE html>
<html>
<head>
<script src="https://fb.me/react-15.1.0.js"></script>
<script src="https://fb.me/react-dom-15.1.0.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div id="container"></div>
<script id="jsbin-javascript">
// similiar to $(function() { ... })
// class is an UI object
// creating a class does not add into DOM yet
var TweetBox = React.createClass({displayName: 'TweetBox',
// In React, you don’t directly modify the DOM. Instead, in an event handler, you modify something called the “state”. And this is done by calling this.setState
// every time state changes, the render function is called again
getInitialState: function(){
return {
text: ''
};
},
handleChange: function(event){
this.setState({ text: event.target.value });
},
// {...} syntax to include any JavaScript code inside the HTML syntax part of JSX.
// add slash for self closing tags
render: function() {
return(
React.createElement("div", {className: "well clearfix"},
React.createElement("textarea", {className: "form-control", onChange: this.handleChange}), React.createElement("br", null),
React.createElement("button", {className: "btn btn-primary", disabled: this.state.text.length === 0}, "Tweet")
)
);
}
});
// render(class_name, container_to_append_into)
ReactDOM.render(
React.createElement(TweetBox, null), document.getElementById('container')
);
</script>
<script id="jsbin-source-javascript" type="text/javascript">// similiar to $(function() { ... })
// class is an UI object
// creating a class does not add into DOM yet
var TweetBox = React.createClass({
// In React, you don’t directly modify the DOM. Instead, in an event handler, you modify something called the “state”. And this is done by calling this.setState
// every time state changes, the render function is called again
getInitialState: function(){
return {
text: ''
};
},
handleChange: function(event){
this.setState({ text: event.target.value });
},
// {...} syntax to include any JavaScript code inside the HTML syntax part of JSX.
// add slash for self closing tags
render: function() {
return(
<div className='well clearfix'>
<textarea className='form-control' onChange = {this.handleChange}></textarea><br/>
<button className='btn btn-primary' disabled = {this.state.text.length === 0}>Tweet</button>
</div>
);
}
});
// render(class_name, container_to_append_into)
ReactDOM.render(
<TweetBox />, document.getElementById('container')
);</script></body>
</html>
// similiar to $(function() { ... })
// class is an UI object
// creating a class does not add into DOM yet
var TweetBox = React.createClass({displayName: 'TweetBox',
// In React, you don’t directly modify the DOM. Instead, in an event handler, you modify something called the “state”. And this is done by calling this.setState
// every time state changes, the render function is called again
getInitialState: function(){
return {
text: ''
};
},
handleChange: function(event){
this.setState({ text: event.target.value });
},
// {...} syntax to include any JavaScript code inside the HTML syntax part of JSX.
// add slash for self closing tags
render: function() {
return(
React.createElement("div", {className: "well clearfix"},
React.createElement("textarea", {className: "form-control", onChange: this.handleChange}), React.createElement("br", null),
React.createElement("button", {className: "btn btn-primary", disabled: this.state.text.length === 0}, "Tweet")
)
);
}
});
// render(class_name, container_to_append_into)
ReactDOM.render(
React.createElement(TweetBox, null), document.getElementById('container')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment