From bb47f14d953adc672521f74e40e51c35e31821d2 Mon Sep 17 00:00:00 2001 From: ysCha Date: Mon, 19 Jan 2026 15:37:39 +0900 Subject: [PATCH] =?UTF-8?q?[1413]=20=EC=A7=80=EB=B6=95=EC=9E=AC=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20api=20=ED=98=B8=EC=B6=9C=20=EB=8B=A4?= =?UTF-8?q?=EC=88=98=20=3D>=20=ED=95=9C=EB=B2=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/common/useMasterController.js | 26 ++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/hooks/common/useMasterController.js b/src/hooks/common/useMasterController.js index f13d3e74..b46adc81 100644 --- a/src/hooks/common/useMasterController.js +++ b/src/hooks/common/useMasterController.js @@ -3,8 +3,11 @@ import { useMessage } from '@/hooks/useMessage' import { useSwal } from '@/hooks/useSwal' import { sessionStore } from '@/store/commonAtom' import { getQueryString } from '@/util/common-utils' -import { useRecoilValue } from 'recoil' +import { atom, useRecoilState, useRecoilValue } from 'recoil' + +// API 요청을 저장할 모듈 레벨 변수 (Hook 외부) +let roofMaterialPromise = null; /** * 마스터 컨트롤러 훅 * @returns @@ -20,10 +23,23 @@ export function useMasterController() { * @returns */ const getRoofMaterialList = async () => { - return await get({ url: '/api/v1/master/getRoofMaterialList' }).then((res) => { - // console.log('🚀🚀 ~ getRoofMaterialList ~ res:', res) - return res - }) + // 1. 이미 진행 중이거나 완료된 Promise가 있으면 그것을 반환 + if (roofMaterialPromise) { + return roofMaterialPromise; + } + + // 2. 처음 호출될 때 Promise를 생성하여 변수에 할당 + roofMaterialPromise = get({ url: '/api/v1/master/getRoofMaterialList' }) + .then((res) => { + return res; + }) + .catch((error) => { + // 에러 발생 시 다음 호출을 위해 초기화 + roofMaterialPromise = null; + throw error; + }); + + return roofMaterialPromise; } /**