diff --git a/src/hooks/useCalendar.ts b/src/hooks/useCalendar.ts index 15be12e..7a24608 100644 --- a/src/hooks/useCalendar.ts +++ b/src/hooks/useCalendar.ts @@ -2,6 +2,7 @@ import { getDaysInMonth } from 'date-fns'; import { useEffect, useMemo, useState } from 'react'; import { useQuery } from 'react-query'; import { getCalendarData } from '../apis/home'; +import useCalendarStore from '../stores/calendarStore'; interface IChatData { dates: string; @@ -21,7 +22,7 @@ const DAY_OF_WEEK = 7; const TWO_DIGIT_FORMAT = 10; const useCalendar = () => { - const [currentDate, setCurrentDate] = useState(new Date()); + const { currentDate, setCurrentDate } = useCalendarStore(); const [formattedDate, setFormattedDate] = useState( `${currentDate.getFullYear()}-${ currentDate.getMonth() + 1 < TWO_DIGIT_FORMAT diff --git a/src/stores/calendarStore.ts b/src/stores/calendarStore.ts new file mode 100644 index 0000000..ad3e672 --- /dev/null +++ b/src/stores/calendarStore.ts @@ -0,0 +1,13 @@ +import create from 'zustand'; + +interface ICalendarStore { + currentDate: Date; + setCurrentDate: (date: Date) => void; +} + +const useCalendarStore = create((set) => ({ + currentDate: new Date(), + setCurrentDate: (date) => set(() => ({ currentDate: date })), +})); + +export default useCalendarStore;