Skip to content

Commit d44e84a

Browse files
refactor: rename todos->todoItems in context
1 parent 990e170 commit d44e84a

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

web/src/contexts/TodoContext.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,42 @@ type Action =
1515
| { type: 'REMOVE_TODO'; payload: TodoItem }
1616
| { type: 'TOGGLE_TODO'; payload: TodoItem }
1717
type Dispatch = (action: Action) => void
18-
type State = { todos: TodoItem[] }
18+
type State = { todoItems: TodoItem[] }
1919
type TodoProviderProps = { children: React.ReactNode }
2020

2121
const TodoContext = createContext<{ state: State; dispatch: Dispatch } | undefined>(undefined)
2222

2323
function 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
}

web/src/features/todos/todo-list/TodoList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const TodoList = () => {
4949
return (
5050
<StyledTodoList>
5151
<AddItem />
52-
{state.todos.map((todo: AddTodoResponse) => (
52+
{state.todoItems.map((todo: AddTodoResponse) => (
5353
<TodoItem key={todo.id} todo={todo} />
5454
))}
5555
</StyledTodoList>

0 commit comments

Comments
 (0)