Created
May 21, 2015 13:26
-
-
Save Shaunakde/19546037076687be80b8 to your computer and use it in GitHub Desktop.
Multi-component in react JS // source http://jsbin.com/zetoco
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://fb.me/react-0.12.0.js"></script> | |
<script src="https://fb.me/JSXTransformer-0.13.3.js"></script> | |
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script> | |
<!-- Latest compiled and minified CSS --> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> | |
<!-- Optional theme --> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css"> | |
<!-- Latest compiled and minified JavaScript --> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> | |
<style id="jsbin-css"> | |
section#outputGroup | |
{ | |
background-color: #CCC; | |
} | |
</style> | |
</head> | |
<body> | |
<section id="textGroup"> | |
<div class="input-group input-group-lg"> | |
<span class="input-group-addon" id="sizing-addon1"><span class="glyphicon glyphicon-star" aria-hidden="true"></span></span> | |
<input type="text" class="form-control" placeholder="Say Something!" aria-describedby="sizing-addon1"> | |
</div> | |
</section> | |
<section id="outputGroup"> | |
<canvas id="outputCanvas"> | |
Outdated Browser | |
</canvas> | |
<div id="app"> | |
<div> | |
</section> | |
<script id="jsbin-javascript"> | |
var TextGroup = React.createClass({displayName: 'TextGroup', | |
render:function(){ | |
return React.createElement("p", null, this.props.text, React.createElement("br", null), React.createElement(Timer, null)) | |
} | |
}); | |
var Timer = React.createClass({displayName: 'Timer', | |
clockTick: function(){ | |
date = new Date(); | |
s= date.getSeconds(); | |
this.setState({work:s}) | |
}, | |
getInitialState: function(){ | |
date = new Date(); | |
s= date.getSeconds(); | |
return ( | |
{ work:s }); | |
}, | |
render:function(){ | |
return React.createElement("p", null, this.state) | |
}, | |
componentDidMount: function(){ | |
setInterval(this.clockTick,1000); | |
} | |
}); | |
React.render(React.createElement(TextGroup, {text: "Shaunak"}), document.getElementById("app")); | |
</script> | |
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html> | |
<html> | |
<head> | |
<script src="//fb.me/react-0.12.0.js"><\/script> | |
<script src="https://fb.me/JSXTransformer-0.13.3.js"><\/script> | |
<script src="https://code.jquery.com/jquery-2.1.3.min.js"><\/script> | |
<\!-- Latest compiled and minified CSS --> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> | |
<\!-- Optional theme --> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css"> | |
<\!-- Latest compiled and minified JavaScript --> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"><\/script> | |
</head> | |
<body> | |
<section id="textGroup"> | |
<div class="input-group input-group-lg"> | |
<span class="input-group-addon" id="sizing-addon1"><span class="glyphicon glyphicon-star" aria-hidden="true"></span></span> | |
<input type="text" class="form-control" placeholder="Say Something!" aria-describedby="sizing-addon1"> | |
</div> | |
</section> | |
<section id="outputGroup"> | |
<canvas id="outputCanvas"> | |
Outdated Browser | |
</canvas> | |
<div id="app"> | |
<div> | |
</section> | |
</body> | |
</html></script> | |
<script id="jsbin-source-css" type="text/css"> | |
section#outputGroup | |
{ | |
background-color: #CCC; | |
}</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var TextGroup = React.createClass({ | |
render:function(){ | |
return <p>{this.props.text}<br/><Timer /></p> | |
} | |
}); | |
var Timer = React.createClass({ | |
clockTick: function(){ | |
date = new Date(); | |
s= date.getSeconds(); | |
this.setState({work:s}) | |
}, | |
getInitialState: function(){ | |
date = new Date(); | |
s= date.getSeconds(); | |
return ( | |
{ work:s }); | |
}, | |
render:function(){ | |
return <p>{this.state}</p> | |
}, | |
componentDidMount: function(){ | |
setInterval(this.clockTick,1000); | |
} | |
}); | |
React.render(<TextGroup text='Shaunak' />, document.getElementById("app")); | |
</script></body> | |
</html> |
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
section#outputGroup | |
{ | |
background-color: #CCC; | |
} |
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
var TextGroup = React.createClass({displayName: 'TextGroup', | |
render:function(){ | |
return React.createElement("p", null, this.props.text, React.createElement("br", null), React.createElement(Timer, null)) | |
} | |
}); | |
var Timer = React.createClass({displayName: 'Timer', | |
clockTick: function(){ | |
date = new Date(); | |
s= date.getSeconds(); | |
this.setState({work:s}) | |
}, | |
getInitialState: function(){ | |
date = new Date(); | |
s= date.getSeconds(); | |
return ( | |
{ work:s }); | |
}, | |
render:function(){ | |
return React.createElement("p", null, this.state) | |
}, | |
componentDidMount: function(){ | |
setInterval(this.clockTick,1000); | |
} | |
}); | |
React.render(React.createElement(TextGroup, {text: "Shaunak"}), document.getElementById("app")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment