1- import { connect } from 'react-redux'
21import React , { useState } from "react" ;
32import { Spinner } from 'reactstrap' ;
4- import { deleteToDo , updateTodo , addTodo , handleTextChange , removeText } from './actions/todoActions' ;
3+ import { useDispatch } from 'react-redux' ;
4+ import { deleteToDo , updateTodo , addTodo } from './actions/todoActions' ;
55
66
7- const handleDelete = ( props , id ) => {
8- props . deleteToDo ( id )
7+ const handleDelete = ( props , id , dispatch ) => {
8+ dispatch ( deleteToDo ( id ) )
99}
1010
11- const handleUpdate = ( e , id , props ) => {
12- props . updateTodo ( id , e . target . checked )
11+ const handleUpdate = ( e , id , props , dispatch ) => {
12+ dispatch ( updateTodo ( id , e . target . checked ) )
1313}
1414
15- const createTodo = ( e , inputValue , setinputValue , props ) => {
15+ const createTodo = ( e , inputValue , setinputValue , props , dispatch ) => {
1616 if ( e . key === 'Enter' ) {
17- props . addTodo ( inputValue )
17+ dispatch ( addTodo ( inputValue ) )
1818 setinputValue ( "" )
1919 }
2020}
2121
22- // const handleChange = (e, props) => {
23- // props.handleTextChange(e.target.value)
24- // }
25-
2622const TodosReduxContainer = ( props ) => {
2723 const [ inputValue , setinputValue ] = useState ( "" ) ;
24+ const dispatch = useDispatch ( ) ;
2825 if ( props && props . todos . length === 0 ) {
2926 return (
3027 < div style = { { textAlign : 'center' } } >
@@ -40,10 +37,10 @@ const TodosReduxContainer = (props) => {
4037 type = "text"
4138 placeholder = "Add a task"
4239 maxLength = "50"
43- onKeyPress = { ( e ) => createTodo ( e , inputValue , setinputValue , props ) }
40+ onKeyPress = { ( e ) => createTodo ( e , inputValue , setinputValue , props , dispatch ) }
4441 value = { inputValue || '' }
4542 // onChange={(e) => handleChange(e, props)}
46- onChange = { e => setinputValue ( e . target . value ) }
43+ onChange = { e => setinputValue ( e . target . value ) }
4744 />
4845 </ div >
4946 < div className = "listWrapper" >
@@ -53,11 +50,11 @@ const TodosReduxContainer = (props) => {
5350 < li className = "task" todo = { todo } key = { todo . id } >
5451 < input className = "taskCheckbox" type = "checkbox"
5552 checked = { todo . done }
56- onChange = { ( e ) => handleUpdate ( e , todo . id , props ) }
53+ onChange = { ( e ) => handleUpdate ( e , todo . id , props , dispatch ) }
5754 />
5855 < label className = "taskLabel" > { todo . title } </ label >
5956 < span className = "deleteTaskBtn"
60- onClick = { ( e ) => handleDelete ( props , todo . id ) } >
57+ onClick = { ( e ) => handleDelete ( props , todo . id , dispatch ) } >
6158 x
6259 </ span >
6360 </ li >
@@ -70,14 +67,4 @@ const TodosReduxContainer = (props) => {
7067 }
7168}
7269
73- const mapDispatchToProps = ( dispatch ) => {
74- return {
75- deleteToDo : ( id ) => { dispatch ( deleteToDo ( id ) ) } ,
76- addTodo : ( data ) => { dispatch ( addTodo ( data ) ) } ,
77- updateTodo : ( id , checked ) => { dispatch ( updateTodo ( id , checked ) ) } ,
78- removeText : ( ) => { dispatch ( removeText ( ) ) } ,
79- handleTextChange : ( data ) => { dispatch ( handleTextChange ( data ) ) }
80- }
81- }
82-
83- export default connect ( null , mapDispatchToProps ) ( TodosReduxContainer )
70+ export default TodosReduxContainer
0 commit comments