Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import logo from './logo.svg';
  3. import './App.css';
  4.  
  5.  
  6. class App extends Component {
  7. constructor(props) {
  8. super(props)
  9. this.state = {
  10. todos:[1, 2, 3, 4],
  11. text: '',
  12. }
  13. }
  14.  
  15. onTextChange(e) {
  16. const value = e.target.value;
  17.  
  18. this.setState({
  19. text: value,
  20. });
  21. }
  22. onClickButton() {
  23. const todos = this.state.todos
  24. todos.push(this.state.text)
  25. this.setState({
  26. todos: todos.slice()
  27. })
  28. }
  29. render() {
  30. return (
  31. <div className="App">
  32. <div className="App-header">
  33. <img src={logo} className="App-logo" alt="logo" />
  34. <h2>Welcome to React</h2>
  35. </div>
  36. <p className="App-intro">
  37. <div className="to-do-list">
  38. <h2>TO DO</h2>
  39. <input type="text" onChange={(e) => this.onTextChange(e)} />
  40. <button onClick={() => this.onClickButton()} >click me</button>
  41. <ul>
  42. {
  43. this.state.todos.map(e => (
  44. <li>{e}</li>
  45. ))
  46. }
  47. </ul>
  48. </div>
  49. </p>
  50. </div>
  51. );
  52. }
  53. }
  54.  
  55. export default App;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement