-
-
Save paggiogriot/01a8706e06d5e5942a29b015a28b86b1 to your computer and use it in GitHub Desktop.
WlcomeApp React Components and message passing between the components; Tutorials @ http://time2hack.com/2016/03/intro-react-js.html & http://time2hack.com/2016/03/todo-app-with-reactjs-and-bootstrap.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
| //WelcomeApp: App Container, houses other components | |
| //and creats underlying servicing methods | |
| var WelcomeApp = React.createClass({ | |
| getInitialState: function(){ | |
| return { name: this.props.name }; | |
| }, | |
| handleKeyUp: function(newVal) { | |
| this.setState( {name: newVal } ); | |
| }, | |
| render: function(){ | |
| return ( | |
| <div> | |
| <WelcomeInput | |
| changeName={this.handleKeyUp.bind(this)} /> | |
| <WelcomeMessage name={this.state.name} /> | |
| </div> | |
| ) | |
| } | |
| }); | |
| //WelcomeInput: Responsible for taking inputs | |
| var WelcomeInput = React.createClass({ | |
| handleKeyUp: function() { | |
| this.props.changeName(this.refs.name.value) | |
| }, | |
| render: function(){ | |
| return ( | |
| <p> | |
| <input type="text" ref="name" | |
| className="form-control" | |
| onKeyUp={this.handleKeyUp} | |
| placeholder="Your Name" /> | |
| </p> | |
| ); | |
| } | |
| }); | |
| //WelcomeMessage: Responsible for feedback to user | |
| var WelcomeMessage = React.createClass({ | |
| render: function(){ | |
| return ( | |
| <p className="lead">Hello {this.props.name}!</p> | |
| ); | |
| } | |
| }); | |
| ReactDOM.render( | |
| <WelcomeApp name='World' />, | |
| document.getElementById('app') | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment