Compare commits
No commits in common. "6268234324b5ee6156809f3287883dae4cf26def" and "0f0af2313197002499f3aedcd2165ce411264a9c" have entirely different histories.
6268234324
...
0f0af23131
@ -3,11 +3,8 @@ 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 { atom, useRecoilState, useRecoilValue } from 'recoil'
|
import { useRecoilValue } from 'recoil'
|
||||||
|
|
||||||
|
|
||||||
// API 요청을 저장할 모듈 레벨 변수 (Hook 외부)
|
|
||||||
let roofMaterialPromise = null;
|
|
||||||
/**
|
/**
|
||||||
* 마스터 컨트롤러 훅
|
* 마스터 컨트롤러 훅
|
||||||
* @returns
|
* @returns
|
||||||
@ -23,23 +20,10 @@ export function useMasterController() {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
const getRoofMaterialList = async () => {
|
const getRoofMaterialList = async () => {
|
||||||
// 1. 이미 진행 중이거나 완료된 Promise가 있으면 그것을 반환
|
return await get({ url: '/api/v1/master/getRoofMaterialList' }).then((res) => {
|
||||||
if (roofMaterialPromise) {
|
// console.log('🚀🚀 ~ getRoofMaterialList ~ res:', res)
|
||||||
return roofMaterialPromise;
|
return res
|
||||||
}
|
})
|
||||||
|
|
||||||
// 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