From 90e0af87ccaaa1b9449aaf519b7c4c485d09f94b Mon Sep 17 00:00:00 2001 From: Nangniya <126762806+Nangniya@users.noreply.github.com> Date: Sat, 17 Feb 2024 01:38:13 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=EC=BA=98=EB=A6=B0=EB=8D=94=20=EB=82=A0?= =?UTF-8?q?=EC=A7=9C=20=EB=8B=A4=EB=A5=B8=20=ED=8E=98=EC=9D=B4=EC=A7=80=20?= =?UTF-8?q?=EA=B0=94=EB=8B=A4=EC=99=80=EB=8F=84=20=EC=9C=A0=EC=A7=80=20(#7?= =?UTF-8?q?7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useCalendar.ts | 3 ++- src/stores/calendarStore.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/stores/calendarStore.ts 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;