From a0bf89b8381e3c7c48388b9ecd2d248cbd232617 Mon Sep 17 00:00:00 2001 From: hyeonjin6530 Date: Wed, 12 Mar 2025 00:26:18 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20api=20=EC=A4=91=EB=B3=B5=20=ED=98=B8?= =?UTF-8?q?=EC=B6=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/mobile/BottomSheet/index.tsx | 23 +++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/components/mobile/BottomSheet/index.tsx b/src/components/mobile/BottomSheet/index.tsx index 680b425..8cd1ace 100644 --- a/src/components/mobile/BottomSheet/index.tsx +++ b/src/components/mobile/BottomSheet/index.tsx @@ -1,6 +1,6 @@ 'use client'; -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, useRef, useCallback } from 'react'; import IconClose from 'public/assets/icons/bottom-sheet/icon-close.svg'; import IconHomeIndicator from 'public/assets/icons/bottom-sheet/icon-home-indicator.svg'; import Image from 'next/image'; @@ -16,6 +16,11 @@ interface BottomSheetProps { item: Item | null; } +function useReRenderer() { + const [, setState] = useState({}); + return useCallback(() => setState({}), []); +} + export default function BottomSheet({ isOpen, onCloseAction, @@ -40,6 +45,10 @@ export default function BottomSheet({ alertMessage: '', }); + // 버튼 중복 클릭 방지 + const isLoadingRef = useRef(false); + const reRender = useReRenderer(); + // 현재 시간 가져오기 (현재 시간 이후로만 입력 가능하도록 하기 위함) const now = new Date(); const currentHour = now.getHours(); @@ -141,6 +150,13 @@ export default function BottomSheet({ return; } + if (isLoadingRef.current) { + return; // 이미 로딩 중이면 무시 + } + + isLoadingRef.current = true; + reRender(); // 렌더링을 강제로 트리거 + try { await requestItems({ itemId: item.itemId, @@ -196,6 +212,9 @@ export default function BottomSheet({ }); }, 300); } + } finally { + isLoadingRef.current = false; + reRender(); // 렌더링을 다시 트리거 } }; @@ -324,7 +343,7 @@ export default function BottomSheet({ quantity === '' || hour === '' || minute === '' - ) + ) || isLoadingRef.current // 로딩 중일 때도 비활성화 } > 대여하기