3. 상품 상세 보기
1. 상품 상세 데이터 받아오기
🎯 상품 상세 정보를 얻어서 보여주는 페이지 구현하기
상품을 찾을 수 없는 경우를 따로 구분해서 표현하면 좋음
지금은 구분하지 않고 그냥 일반 에러로 표시할 것
ProductDetailPage.tsx
작성
ProductDetailPage.tsx
작성useFetchProduct에서 loading과 error를 받아 화면에 표현하기
Loading
Error
ProductDetail
useProductDetailStore hook 생성
src/hooks
tsyringe의 container를 이용해
ProductDetailStore
를 활용
ProductDetailStore.ts
생성
ProductDetailStore.ts
생성src/stores
구현 내용
로딩 시작
loading = true
error = false
apiService.fetchProduct({productId})
ApiService에서 fetchProduct 구현
data를 그대로 product로 내보내기
로딩 끝
loading = false, error는 상태 봐서 처리
product
타입 지정
Null Object를 생성
@Action() 추가
startLoading
setProduct
setError
Null Object 생성
Special Case(null object pattern)
types.ts의 하단에 생성하거나 그 외의 곳도 가능
useFetchProduct hook 생성
src/hooks
2. 상품 상세 페이지 UI 구현하기
장바구니 담기 기능 때문에 prop drilling 문제가 발생할 수 있어서, Page에서 product를 내려주지 않게 처리
ProductDetail 컴포넌트에서 product만 얻어서 활용할 것
ProductDetail.tsx
컴포넌트 구현
ProductDetail.tsx
컴포넌트 구현src/components/product-detail/ProductDetail.tsx
구현 내용
Store 에서 상품 정보 얻기 - fetch는 page에서 처리
보여주기
Images 컴포넌트 생성
Description 컴포넌트 생성
임의로 key를 잡아주기 위해 컴포넌트 밖에서
function key(text, index)
를 생성
Last updated