Created
July 23, 2015 17:06
-
-
Save Ortuna/223deeec5dd3f18af696 to your computer and use it in GitHub Desktop.
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 UserAdder = React.createClass({ | |
getInitialState: function() { | |
return {name: ''} | |
}, | |
changeHandler: function(e) { | |
this.setState({name: e.target.value}); | |
}, | |
appendUser: function() { | |
this.props.callback(this.state.name); | |
}, | |
render: function() { | |
return(<div> | |
<input type="text" onChange={this.changeHandler}></input> | |
<button type="submit" onClick={this.appendUser}>Add</button> | |
</div>) | |
}, | |
}); | |
var HelloMessage = React.createClass({ | |
getInitialState: function() { | |
return {users: []}; | |
}, | |
getUserList: function() { | |
var list = []; | |
for(var i = 0; i < this.state.users.length; i++) { | |
list.push(<li>{this.state.users[i]}</li>); | |
} | |
return list; | |
}, | |
addUser: function(userName) { | |
var list = this.state.users; | |
list.push(userName); | |
this.setState({users: list}); | |
}, | |
render: function() { | |
return (<ul> | |
{this.getUserList()} | |
<UserAdder callback={this.addUser} /> | |
</ul>) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment