Open
Conversation
limtjdghks
reviewed
Sep 28, 2025
Comment on lines
+5
to
+30
| const Todo = () => { | ||
| const { todos, doneTodos, deleteTodo, completeTodo } = useTodo(); | ||
|
|
||
| return ( | ||
| <div className="todo-container"> | ||
| <h1 className="todo-container__header">YONG TODO</h1> | ||
| <TodoForm /> | ||
| <div className="render-container"> | ||
| <TodoList | ||
| title="할 일" | ||
| todos={todos} | ||
| buttonLabel="완료" | ||
| buttonColor="#28a745" | ||
| onClick={completeTodo} | ||
| /> | ||
| <TodoList | ||
| title="완료" | ||
| todos={doneTodos} | ||
| buttonLabel="삭제" | ||
| buttonColor="#dc3545" | ||
| onClick={deleteTodo} | ||
| /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; |
Member
There was a problem hiding this comment.
useContext는 부모 컴포넌트와 하위 컴포넌트간의 props 전달을 줄이기 위해 state를 전역으로 관리 할 수 있도록 사용하는 훅입니다 Todo.tsx 컴포넌트에서 deleteTodo, completeTodo를 호출한 뒤 TodoList.tsx로 전달하면 useContext를 사용하는 것 보다 TodoList.tsx 컴포넌트에서 각각 state와 함수를 호출하여 사용하는 것이 적절한 것 같습니다
const TodoList = ( {title,
todos,
buttonLabel,
buttonColor}: TodoListProps ) => {
const { deleteTodo, completeTodo } = useTodo();
return (
<div className="render-container__section">
<h2 className="render-container__title">{title}</h2>
<ul id="todo-list" className="render-container__list">
{todos?.map(
(todo): React.ReactElement => (
<li key={todo.id} className="render-container__item">
<span className="render-container__item-text">
{todo.text}
</span>
<button
onClick={() => onClick(todo)}
style={{ backgroundColor: buttonColor }}
className="render-container__item-button"
>
{buttonLabel}
</button>
</li>
)
)}
</ul>
</div>
);
};TodoList.tsx에서 todos,doneTodos state도 props 전달 없이 useContext를 사용할 수 있는 로직을 구성해보는 것도 추천드립니다
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
useContext를 이용하여 전역으로 상태를 관리하며 TodoList를 좀 더 효율적으로 관리 하는 방법을 알게 되어 좋았습니다.