[1413] 지붕재 목록 api 호출 다수 => 한번
This commit is contained in:
parent
97b3a8c2ba
commit
bb47f14d95
@ -3,8 +3,11 @@ import { useMessage } from '@/hooks/useMessage'
|
|||||||
import { useSwal } from '@/hooks/useSwal'
|
import { useSwal } from '@/hooks/useSwal'
|
||||||
import { sessionStore } from '@/store/commonAtom'
|
import { sessionStore } from '@/store/commonAtom'
|
||||||
import { getQueryString } from '@/util/common-utils'
|
import { getQueryString } from '@/util/common-utils'
|
||||||
import { useRecoilValue } from 'recoil'
|
import { atom, useRecoilState, useRecoilValue } from 'recoil'
|
||||||
|
|
||||||
|
|
||||||
|
// API 요청을 저장할 모듈 레벨 변수 (Hook 외부)
|
||||||
|
let roofMaterialPromise = null;
|
||||||
/**
|
/**
|
||||||
* 마스터 컨트롤러 훅
|
* 마스터 컨트롤러 훅
|
||||||
* @returns
|
* @returns
|
||||||
@ -20,10 +23,23 @@ export function useMasterController() {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
const getRoofMaterialList = async () => {
|
const getRoofMaterialList = async () => {
|
||||||
return await get({ url: '/api/v1/master/getRoofMaterialList' }).then((res) => {
|
// 1. 이미 진행 중이거나 완료된 Promise가 있으면 그것을 반환
|
||||||
// console.log('🚀🚀 ~ getRoofMaterialList ~ res:', res)
|
if (roofMaterialPromise) {
|
||||||
return res
|
return roofMaterialPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 처음 호출될 때 Promise를 생성하여 변수에 할당
|
||||||
|
roofMaterialPromise = get({ url: '/api/v1/master/getRoofMaterialList' })
|
||||||
|
.then((res) => {
|
||||||
|
return res;
|
||||||
})
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
// 에러 발생 시 다음 호출을 위해 초기화
|
||||||
|
roofMaterialPromise = null;
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
|
||||||
|
return roofMaterialPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user