Last active
June 17, 2017 14:21
-
-
Save santiagobasulto/2ce8de068f9940ef418813684515ea1e to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
| <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> |
This file contains hidden or 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
| 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')); |
This file contains hidden or 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
| 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