Skip to content

Instantly share code, notes, and snippets.

@overthemike
Created March 23, 2017 23:38
Show Gist options
  • Save overthemike/a9b3a062638bfa74b9a9b460b5e903bd to your computer and use it in GitHub Desktop.
Save overthemike/a9b3a062638bfa74b9a9b460b5e903bd to your computer and use it in GitHub Desktop.
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