Skip to content

Commit

Permalink
Fix: 캘린더 날짜 다른 페이지 갔다와도 유지 (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nangniya authored Feb 16, 2024
1 parent bbcbc55 commit 90e0af8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/hooks/useCalendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/stores/calendarStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import create from 'zustand';

interface ICalendarStore {
currentDate: Date;
setCurrentDate: (date: Date) => void;
}

const useCalendarStore = create<ICalendarStore>((set) => ({
currentDate: new Date(),
setCurrentDate: (date) => set(() => ({ currentDate: date })),
}));

export default useCalendarStore;

0 comments on commit 90e0af8

Please sign in to comment.