Skip to content

Commit ef9e4bc

Browse files
authored
Merge pull request #95 from cortex-reply/fix-timezone-holiday-issue
fix issue with server/client rendering clash
2 parents 711c154 + db03fe0 commit ef9e4bc

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/components/Holidays/RequestLeave.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,15 @@ export function RequestLeave({ remainingDays, submitLeaveRequest }: RequestLeave
5050
return new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0))
5151
}
5252

53-
const [startDate, setStartDate] = useState<Date | undefined>(() => setToMidnightUTC(new Date()))
54-
const [endDate, setEndDate] = useState<Date | undefined>(() => setToMidnightUTC(new Date()))
53+
const [startDate, setStartDate] = useState<Date | undefined>(undefined)
54+
const [endDate, setEndDate] = useState<Date | undefined>(undefined)
55+
56+
// Set initial dates on client only to avoid hydration mismatch
57+
useEffect(() => {
58+
if (startDate === undefined) setStartDate(setToMidnightUTC(new Date()))
59+
if (endDate === undefined) setEndDate(setToMidnightUTC(new Date()))
60+
// eslint-disable-next-line react-hooks/exhaustive-deps
61+
}, [])
5562
const [leaveType, setLeaveType] = useState('Full Day')
5663
const [isMultipleDays, setIsMultipleDays] = useState(false)
5764
const [totalDays, setTotalDays] = useState(1)

0 commit comments

Comments
 (0)