22 lines
707 B
TypeScript
22 lines
707 B
TypeScript
|
|
import { useEffect } from 'react';
|
||
|
|
import { useCalendarScheduleStore } from '@/stores/useCalendarScheduleStore';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 달력 일정 데이터를 스토어에 초기 로드하는 경량 훅
|
||
|
|
*
|
||
|
|
* 지정된 연도의 공휴일/세무일정/회사일정이 아직 로드되지 않았으면
|
||
|
|
* API를 호출하여 Zustand 스토어에 캐시합니다.
|
||
|
|
*
|
||
|
|
* @param year 로드할 연도
|
||
|
|
*/
|
||
|
|
export function useCalendarScheduleInit(year: number) {
|
||
|
|
const fetchSchedules = useCalendarScheduleStore((s) => s.fetchSchedules);
|
||
|
|
const loaded = useCalendarScheduleStore((s) => s.loadedYears[year]);
|
||
|
|
|
||
|
|
useEffect(() => {
|
||
|
|
if (!loaded) {
|
||
|
|
fetchSchedules(year);
|
||
|
|
}
|
||
|
|
}, [year, loaded, fetchSchedules]);
|
||
|
|
}
|