Feat: Week7/nonshaman-m2#71
Open
nonshaman wants to merge 16 commits into
Open
Conversation
Feat: Week3/nonshaman m1
feat: 3주차 미션 2 진행 (fix)
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
yewon20804
reviewed
May 19, 2026
Collaborator
yewon20804
left a comment
There was a problem hiding this comment.
7주차 미션2 확인했습니다 ! 낙관적 업데이트 개념을 이해하고 좋아요 기능을 구현해보는거였는데요! 😀
코멘트 확인 부탁드립니다 ~
1. useDeleteLike.ts / useAddLike.ts — onMutate에서 cancelQueries 누락
// ❌ 현재
onMutate: async (lpId) => {
const previousData = queryClient.getQueryData(['likes', lpId]);
queryClient.setQueryData(['likes', lpId], (old) => ...);
return { previousData };
},
// ✅ 수정
onMutate: async (lpId) => {
await queryClient.cancelQueries({ queryKey: ['likes', lpId] });
const previousData = queryClient.getQueryData(['likes', lpId]);
queryClient.setQueryData(['likes', lpId], (old) => ...);
return { previousData };
},
cancelQueries 없이 바로 setQueryData를 하면, 기존 요청 응답이 나중에 도착하면서 방금 바꾼 값이 다시 덮어써질 수 있어서 먼저 취소해두는 게 안전할 것 같습니다!
2. useDeleteLike.ts / useAddLike.ts — onError에서 rollback 처리 필요
// ❌ 현재
onError: (error) => {
console.error(error);
},
// ✅ 수정
onError: (error, lpId, context) => {
// 실패하면 이전 데이터로 복구!
if (context?.previousData) {
queryClient.setQueryData(['likes', lpId], context.previousData);
}
},
서버 요청이 실패했을 때 UI를 원래대로 되돌려야 합니다 ! onMutate에서 반환한 context를 사용하시면 좋습니다 😀
3. useDeleteLike.ts / useAddLike.ts — onSettled에서 invalidateQueries 필요
// ❌ 현재
// ✅ 수정
onSettled: (data, error, lpId) => {
// 성공/실패 모두 서버 최신 데이터로 갱신
queryClient.invalidateQueries({ queryKey: ['likes', lpId] });
},
낙관적 업데이트를 사용하더라도 실제 서버 상태와 달라질 수 있어서, onSettled에서 invalidateQueries로 한 번 최신 데이터를 다시 가져와주는 게 안전할 것 같습니다!
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.
📚 주차 / 미션
📌 작업 내용
✨ 상세 작업 내용
📸 스크린샷
✅ 체크리스트