✨[Feat] api 수정 및 추가 사항 적용 #293
Merged
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.
#️⃣연관된 이슈
📝작업 내용
모임 목록 조회 페이지
모임 상세 페이지
미리보기 및 결과물
찜하기 클릭 시 UI 즉각 적용
default.mp4
💬리뷰 요구사항
낙관적 업데이트를 사용하여 찜하기 UI 딜레이 문제를 해결했어요!
문제 상황
찜하기 버튼을 클릭했을 때, 찜 상태가 즉시 반영되지 않고 두 번 클릭해야 상태가 반영됨.
원인 분석
invalidateQueries호출 → 캐시 무효화 → 서버에서 데이터 다시 가져옴 (추가 시간 소요)즉, 두 번 클릭이 필요했던 이유는
invalidateQueries로 캐시를 무효화한 후 네트워크 요청이 완료되기까지 시간이 걸리기 때문입니다.해결
invalidateQueries는 캐시 무효화를 초래하여 UI와 데이터 동기화에 텀을 유발하므로 제거합니다.찜하기를 클릭했을 때 UI가 바로 반영되고 있습니다만... 로직이 맞는지는 확신이 없네요...ㅎㅎ
기타 참고사항
낙관적 업데이트(Optimistic Update)란?
낙관적 업데이트는 사용자가 요청을 보냈을 때, 서버 응답을 기다리지 않고 UI를 먼저 업데이트하는 방법이다.
사용자가 보는 화면을 즉각적으로 반영함으로써 더 빠르고 부드러운 사용자 경험(UX)을 제공한다.
💡 주요 동작 과정
요청이 성공할 것이라고 가정(낙관적으로 생각)하고 UI 상태를 변경한다.
요청이 실패하면 이전 상태로 돌아가도록 데이터를 복구한다.
서버에서 최신 데이터를 받아 캐시를 업데이트한다.