Skip to content

Instantly share code, notes, and snippets.

@santiagobasulto
Last active June 17, 2017 14:21
Show Gist options
  • Save santiagobasulto/2ce8de068f9940ef418813684515ea1e to your computer and use it in GitHub Desktop.
Save santiagobasulto/2ce8de068f9940ef418813684515ea1e to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Hello React!</title>
</head>
<body>
<!-- DOM element to insert React components -->
<div id="app"></div>
<!-- React libraries -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.10.3/babel.min.js"></script>
<script src="https://cdn.jsdelivr.net/lodash/4.13.1/lodash.min.js"></script>
<!-- Main code -->
<script type="text/babel" src="main.js"></script>
</body>
</html>
class WorldClock extends React.Component {
constructor(){
super();
var ba = new Date();
var est = new Date();
var pst = new Date();
est.setHours(ba.getHours() - 1);
pst.setHours(ba.getHours() - 4);
this.state = {ba, est, pst}
console.log(this.state)
}
addTenSeconds(){
// console.log("Button clicked")
var ba = new Date();
var plus10 = new Date();
var min10 = new Date();
plus10.setHours(ba.getHours() + 10);
min10.setHours(ba.getHours() - 10);
this.setState({ba: plus10})
}
render() {
let times = _.map(this.state, (time, key) => {
return <li key={key}>{time.toTimeString()}</li>
});
return <div>
<button onClick={this.addTenSeconds.bind(this)}>Add ten seconds</button>
<ul>
{times}
</ul>
</div>
}
}
ReactDOM.render(
<WorldClock />,
document.getElementById('app'));
class BasicInput extends React.Component {
constructor(){
super();
this.state = {
myTextValue: ''
}
}
handleTextChange(evt){
this.setState({
myTextValue: evt.target.value
})
// console.log(evt.target.value)
}
render() {
return <div>
<input type="text" onChange={this.handleTextChange.bind(this)} value={this.state.myTextValue} />
</div>
}
}
ReactDOM.render(
<BasicInput />,
document.getElementById('app'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment