@@ -15,42 +15,42 @@ type Action =
1515 | { type : 'REMOVE_TODO' ; payload : TodoItem }
1616 | { type : 'TOGGLE_TODO' ; payload : TodoItem }
1717type Dispatch = ( action : Action ) => void
18- type State = { todos : TodoItem [ ] }
18+ type State = { todoItems : TodoItem [ ] }
1919type TodoProviderProps = { children : React . ReactNode }
2020
2121const TodoContext = createContext < { state : State ; dispatch : Dispatch } | undefined > ( undefined )
2222
2323function TodoProvider ( { children } : TodoProviderProps ) {
24- const [ state , dispatch ] = useReducer ( todoReducer , { todos : [ ] } )
24+ const [ state , dispatch ] = useReducer ( todoReducer , { todoItems : [ ] } )
2525 const value = { state, dispatch }
2626
2727 return < TodoContext . Provider value = { value } > { children } </ TodoContext . Provider >
2828}
2929
30- function todoReducer ( state : State , action : Action ) {
30+ function todoReducer ( state : State , action : Action ) : State {
3131 switch ( action . type ) {
3232 case 'ADD_TODO' : {
3333 return {
3434 ...state ,
35- todos : [ ...state . todos , action . payload ] ,
35+ todoItems : [ ...state . todoItems , action . payload ] ,
3636 }
3737 }
3838 case 'INITIALIZE' : {
3939 return {
4040 ...state ,
41- todos : action . payload ,
41+ todoItems : action . payload ,
4242 }
4343 }
4444 case 'REMOVE_TODO' : {
4545 return {
4646 ...state ,
47- todos : state . todos . filter ( ( todo ) => todo . id !== action . payload . id ) ,
47+ todoItems : state . todoItems . filter ( ( todo ) => todo . id !== action . payload . id ) ,
4848 }
4949 }
5050 case 'TOGGLE_TODO' : {
5151 return {
5252 ...state ,
53- todos : state . todos . map ( ( todo ) =>
53+ todoItems : state . todoItems . map ( ( todo ) =>
5454 todo !== action . payload ? todo : { ...todo , is_completed : ! todo . is_completed }
5555 ) ,
5656 }
0 commit comments