From 7fcfe216a7412ece90dc18161406306ceeb568c6 Mon Sep 17 00:00:00 2001 From: Sanghyeon Sim <5338095@gmail.com> Date: Fri, 1 Sep 2023 23:41:30 +0900 Subject: [PATCH] fix: kakao shop index correction --- source/component/ShopPost.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/source/component/ShopPost.js b/source/component/ShopPost.js index a6f81e4..022faa7 100644 --- a/source/component/ShopPost.js +++ b/source/component/ShopPost.js @@ -277,13 +277,18 @@ const ShopPost = ({userId, category, setStoreName}) => { } const response = await fetchKakaoShops(shopTitle, category); setKakaoShops(response.data['documents']); - setLatitude(response.data['documents'][0].y); - setLongitude(response.data['documents'][0].x); - setPhoneNumber(response.data['documents'][0].phone); - setPlaceUrl(response.data['documents'][0].place_url); + if (response.data['documents'].length == 0) return; setSelectedShopIndex(0); }; + React.useEffect(() => { + if (kakaoShops.length == 0) return; + setLatitude(kakaoShops[selectedShopIndex].y); + setLongitude(kakaoShops[selectedShopIndex].x); + setPhoneNumber(kakaoShops[selectedShopIndex].phone); + setPlaceUrl(kakaoShops[selectedShopIndex].place_url); + }, [selectedShopIndex]); + React.useEffect(() => { searchKakaoShops(); }, [shopTitle]);