Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. import React from 'react';
  2.  
  3. export default React.createClass({
  4. getInitialState: function() {
  5. return {
  6. list: [],
  7. text: ''
  8. }
  9. },
  10.  
  11. // ["take out trash", "call your mom", "tell mom you love her"]
  12. // "mow the lawn"
  13.  
  14. // ["mow the lawn", "take out trash", "call your mom", "tell mom you love her"]
  15.  
  16.  
  17. handleChange: function(e) {
  18. this.setState({
  19. text: e.target.value
  20. })
  21. },
  22.  
  23. handleSubmit: function(e) {
  24. e.preventDefault()
  25. this.setState({
  26. list: [this.state.text, ...this.state.list],
  27. text: ''
  28. })
  29. },
  30.  
  31. render: function () {
  32. return (
  33. <form onSubmit={this.handleSubmit}>
  34. <input type="text" onChange={this.handleChange} value={this.state.text} />
  35. </form>
  36. )
  37. }
  38. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement