Open
Conversation
Member
// 원래 코드
useEffect(() => {
setCount(0);
for (const todo of todos) {
if (todo.complete === true) setCount(count+1);
}
}, [todos]);map을 쓰지 않고 for ... of를 쓰신거 정말 잘하셨습니다! 어떻게 두 개의 차이점을 벌써 알고계신거죠?? 대단합니다. // 수정 코드(한번만 계산)
useEffect(() => {
const completedCount = todos.filter(todo => todo.complete).length;
setCount(completedCount);
}, [todos]);(App.jsx에서 filter를 쓰셔서 말하는거에요! filter를 사용하실 줄 아는 당신은 javascript 고수) |
Member
|
input을 useRef로 관리 하는 방식도 괜찮습니다. const [inputValue, setInputValue] = useState('');이런 state 하나를 만들어서 관리하는 것이 어떨까요? 요구사항 때문에 어쩔 수 없었던 건 알지만, 실제로 코드를 짜실 때는 해당 방식(useState)으로 사용하시길 권장드립니다. |
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.
No description provided.