Guest User

Untitled

a guest
Feb 25th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. import React from 'react'
  2. import { connect } from 'react-redux'
  3. import { addTodo, addTodoAsync } from '../actions'
  4.  
  5. let AddTodo = ({ dispatch }) => {
  6. let input
  7.  
  8. return (
  9. <div>
  10. <form onSubmit={e => {
  11. e.preventDefault()
  12. if (!input.value.trim()) {
  13. return
  14. }
  15.  
  16. dispatch(addTodoAsync(input.value)).then(() => {
  17. console.log('done!');
  18. })
  19.  
  20. input.value = ''
  21. }}>
  22. <input ref={node => {
  23. input = node
  24. }} />
  25. <button type="submit">
  26. Add Todo
  27. </button>
  28. </form>
  29. </div>
  30. )
  31. }
  32. AddTodo = connect()(AddTodo)
  33.  
  34. export default AddTodo
Add Comment
Please, Sign In to add comment