Skip to content

Commit

Permalink
fix: 달력 업데이트에 useEffect 사용
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcjy committed Sep 19, 2024
1 parent b167492 commit a32464d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions components/calendar/Calendar.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use client'
import { useMemo, useState, useCallback } from 'react'
import { BibleData } from './types'
import { useMemo, useState, useCallback, useEffect } from 'react'
import { BibleData, DayData } from './types'
import { CalendarHeader } from './CalendarHeader'
import { CalendarNav } from './CalendarNav'
import { CalendarGrid } from './CalendarGrid'

export const Calendar = ({ bibleData }: { bibleData: BibleData }) => {
const [currentDate, setCurrentDate] = useState(new Date())
const [calendar, setCalendar] = useState<DayData[]>([])
const [today, setToday] = useState(new Date())

const createCalendar = useCallback(
Expand Down Expand Up @@ -54,10 +55,10 @@ export const Calendar = ({ bibleData }: { bibleData: BibleData }) => {
[bibleData, today]
)

const calendar = useMemo(
() => createCalendar(currentDate),
[currentDate, createCalendar]
)
useEffect(() => {
const calendar = createCalendar(currentDate)
setCalendar(calendar)
}, [currentDate])

const changeMonth = useCallback((d: number) => {
setCurrentDate(
Expand Down

0 comments on commit a32464d

Please sign in to comment.