[6주차 과제] Tanstack Query 연습 - #8
Open
soyyyyy wants to merge 48 commits into
Open
Conversation
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.
🏡 과제 명세
💡 과제
any사용 금지✍️ 구현 요약 및 새로 배운 점
폴더 구조
영화 목록 / 상세 페이지 기준으로 apis, components, types, constants, utils 등를 나눠서 관리했습니다.
절대 경로 설정
상대 경로가 길어지는 걸 줄이기 위해
shared/,pages폴더 대상으로 path alias를 설정했습니다.가장 짧은 경로를 사용할 수 있도록 했습니다. (예: shared/constants → @constants)
라우터 설정
path를 상수화했고, 각 페이지에 이미지가 많으므로 로딩 속도를 개선하기 위해 lazy loading 적용했습니다.
API 공통 구조
endpoint 상수화, 공통 HTTP 구조, axios 공통 설정을 분리해 관리했습니다.
endpoint 상수화
공통 HTTP wrapper 구조
각 api 함수에서
response.data를 매번 꺼내지 않아도 되게 설정했고, 이번 과제에서 필요한 get, post, delete만 정의했습니다.axios 공통 설정
TanStack Query 도입
목록 조회, 상세 조회, 별점 관련 요청을 쿼리/뮤테이션으로 나누어 구현했습니다. 이 과정에서 둘 다 사용되는 상세페이지에서는
apis폴더 밑에queries,mutations폴더를 별도로 두었습니다.상세페이지의 데이터를 UI 용으로 가공
상세페이지에서 사용되는 label이 많아서 이를 상수화 하고, API 응답을 각 label에 맞게 가공했습니다.
게스트 세션 발급
게스트 세션 id가 없으면 새로 발급받고, 있으면 재사용하도록 했습니다.
처음에 이 부분도
axiosInstance에서 공통 처리하려고 했는데, 서버로 보내는 방식이 params, path로 각각 달라서 제외했습니다.💦 구현 과정에서 어려웠던 & 고민했던 부분
TMDB 이미지 변환
TMDB 응답의
poster_path,backdrop_path는 완성 URL(https:// ~)이 아니라 상대 경로라서, UI에서 바로 매핑하니 이미지가 깨지는 문제가 있었습니다.이 문제를 해결하기 위해 아래처럼 util을 분리해 사용했습니다. 영화 목록/상세 페이지에서 각각 필요한 크기(size)만 다르게 넣을 수 있습니다. (참고자료)
무한 스크롤 단계별 구현
useInfiniteQuery만 붙인다고 끝나는 게 아니라,pageParam, getNextPageParam, IntersectionObserver, hasNextPage, isFetchingNextPage를 같이 이해해야 해서 흐름을 잡기 어려웠습니다.특히 단계별로 스크롤이 진행되지 않고, 계속 요청이 나가는 문제가 있었습니다.(UI도 안 그려짐.)
원인
fetchNextPage()가 컴포넌트 최상단에서 렌더링마다 호출되어, 스크롤과 무관하게 모든 페이지를 한 번에 불러왔습니다.해결방법
Intersection Observer로 리스트 하단 요소가 뷰포트에 진입할 때만
fetchNextPage()를 호출하도록 변경했습니다.추가적으로 스크롤 튕김 현상이 심했는데, grid auto-fit 은 레이아웃을 재계산 하기 때문에
auto-fill변경하면 이를 방지할 수 있다는 점을 알게 되었습니다.input 초기값 관리
저장된 별점이 있으면 input에 넣거나 삭제할 경우 input의 값을 없애는 작업에서 의도한대로 잘 동작이 되지 않았습니다.
최종적으로는 초기 rating이 바뀔 때 key를 바꿔 컴포넌트를 다시 마운트하는 방식으로 수정해 해결했습니다.
🙋♀️ 리뷰 요청 포인트 & 질문
📷 결과물
2026-06-02.10.07.35.1.1.1.mov