Created
March 23, 2017 23:38
-
-
Save overthemike/a9b3a062638bfa74b9a9b460b5e903bd 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
import React from 'react'; | |
export default React.createClass({ | |
getInitialState: function() { | |
return { | |
list: [], | |
text: '' | |
} | |
}, | |
// ["take out trash", "call your mom", "tell mom you love her"] | |
// "mow the lawn" | |
// ["mow the lawn", "take out trash", "call your mom", "tell mom you love her"] | |
handleChange: function(e) { | |
this.setState({ | |
text: e.target.value | |
}) | |
}, | |
handleSubmit: function(e) { | |
e.preventDefault() | |
this.setState({ | |
list: [this.state.text, ...this.state.list], | |
text: '' | |
}) | |
}, | |
render: function () { | |
return ( | |
<form onSubmit={this.handleSubmit}> | |
<input type="text" onChange={this.handleChange} value={this.state.text} /> | |
</form> | |
) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment