Skip to content

Feat: 2주차 미션1#13

Open
soyun0318 wants to merge 1 commit intomainfrom
week2/sori-m1
Open

Feat: 2주차 미션1#13
soyun0318 wants to merge 1 commit intomainfrom
week2/sori-m1

Conversation

@soyun0318
Copy link
Copy Markdown
Collaborator

📚 주차 / 미션

  • 2주차 1번째 미션

📌 작업 내용

  • Chapter 01에서 만든 TypeScript 기반 To-Do List를 React 환경으로 리팩토링

✨ 상세 작업 내용

  1. App.tsx 하나의 파일에서 먼저 기능 완성
  2. 컴포넌트 단위로 분리
  3. contextAPI를 활용해 props-drilling 문제 해결

📸 스크린샷

image

❓ 리뷰어가 알아야 할 사항 / 질문


✅ 체크리스트

  • [ ✅] 기능 정상 작동 확인
  • [ ✅] 불필요한 주석 삭제
  • [ ✅] 해당 주차 키워드 내용 이해

deleteTask: (task: Task) => void;
}

export const TodoContext = createContext<TodoContextType | undefined>(undefined);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined은 '값이 아직 안 들어옴', null은 '의도적으로 비워둠' 의미가 강합니다! undefined로 해도 동일하게 작동하지만 의미를 명확하게 하기위해 초기값은 null를 사용하는 것이 더 적절해 보입니다☺️

const [doneTasks, setDoneTasks] = useState<Task[]>([]);

const addTodo = (text: string) => {
setTodos([...todos, {id: Date.now(), text }]);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state는 비동기로 업데이트되기 때문에, todos를 직접 참조하면 이전 상태값을 참조하는 stale state 문제가 발생할 수 있습니다! setTodos에 prev를 받는 함수형 업데이트를 사용하면 더 안전하게 동작합니다 :) completeTask, deleteTask도 마찬가지로 적용해보면 좋을 것 같아요☺️

const TodoInput = () => {
const [value, setValue] = useState('');

const context = useContext(TodoContext);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 각 컴포넌트에서 useContext(TodoContext)를 직접 호출하고 조건문 체크를 반복하고 있는데, 컴포넌트가 많아질수록 코드가 복잡해질 수 있을 것 같습니다! TodoContext.tsx에 커스텀 훅을 정의하고 컴포넌트에서는 이를 호출하는 방식으로 분리하면 더 깔끔하게 관리할 수 있을 것 같아요!

import { type Task } from '../types';
import TodoItem from './TodoItem';

interface TodoLiskProps {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

인터페이스 이름에 오타가 있는 것 같아요 ! Lisk -> List 로 수정하면 좋을 것 같습니다 !


createRoot(document.getElementById('root')!).render(
<StrictMode>
<TodoProvider>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 App.tsx와 main.tsx 파일 둘다에서 TodoProvider로 감싸고 있어, Context가 이중으로 생성되고 있습니다! 이렇게 되면 각 파일이 서로 다른 독립적인 상태를 가지게 되어 의도치 않은 동작이 나타날 수 있습니다 ! main에 있는 Provider는 제거하고 App.tsx에서만 사용하는 것이 좋을 것 같아요 ☺️

@@ -0,0 +1,27 @@
import { useState } from 'react';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용하지 않은 import문은 제거해주시는게 좋아요 👍

Copy link
Copy Markdown
Collaborator

@yewon20804 yewon20804 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

미션 수고하셨습니다 ! TodoList에서 타입을 유니온으로 하여 하나의 컴포넌트에서 처리한 부분이 좋은 것 같아요 ! 코드리뷰 확인해주시면 감사하겠습니다 -!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants