Guest User

Untitled

a guest
Jan 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { bindActionCreators } from 'redux';
  3. import { connect } from 'react-redux';
  4.  
  5. function addTodo (task) {
  6. return {type:"ADD",payload:task}
  7. }
  8.  
  9. class App extends Component {
  10. state = {
  11. task: '',
  12. }
  13.  
  14. handleChange(e) {
  15. this.setState({task:e.target.value})
  16. }
  17.  
  18. render() {
  19. return (
  20. <div className="App">
  21. <input type='text' value={this.state.task} onChange = {(e) => this.handleChange(e)}/>
  22. <button type='button' onClick={()=>this.props.addTodo(this.state.task)} >Add</button>
  23. <div>{this.props.todos.map(task => (<h1>{task}</h1>))}</div>
  24. </div>
  25. );
  26. }
  27. }
  28.  
  29. function mapStateToProps (state) {
  30. return {
  31. todos:state.todos
  32. }
  33. }
  34.  
  35. export default connect(mapStateToProps,{ addTodo })(App);
Add Comment
Please, Sign In to add comment