Skip to content

Commit b188739

Browse files
committed
Fix hydration errors in PomodoroTimer
1 parent d7d608f commit b188739

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

components/PomodoroTimer.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
PopoverArrow,
1313
useMediaQuery,
1414
} from '@chakra-ui/react'
15-
import { ReactElement, useReducer } from 'react'
15+
import { ReactElement, useEffect, useReducer, useState } from 'react'
1616
import { FaGraduationCap } from 'react-icons/fa'
1717
import { IoTimerOutline } from 'react-icons/io5'
1818
import {
@@ -137,13 +137,26 @@ export const PomodoroTimer = (props: any) => {
137137
const { isRunning, status, timeRemaining } = state
138138

139139
const { variant, ...rest } = props
140-
const [isBigScreen] = useMediaQuery('(min-width: 62em)')
141-
const maxPopoverWidth = isBigScreen ? '14rem' : '11rem'
140+
const [isBigScreenMediaQuery] = useMediaQuery('(min-width: 62em)')
141+
const [isBigScreen, setIsBigScreen] = useState(false)
142+
const [maxPopoverWidth, setMaxPopoverWidth] = useState('14rem')
143+
144+
useEffect(() => {
145+
setIsBigScreen(isBigScreenMediaQuery)
146+
}, [isBigScreenMediaQuery])
147+
148+
useEffect(() => {
149+
setMaxPopoverWidth(isBigScreen ? '14rem' : '11rem')
150+
}, [isBigScreen])
142151

143152
const timerStyle = useStyleConfig('PomodoroTimer', { variant })
144153
const iconStyle = useStyleConfig('PomodoroIcon', { variant })
145154

146-
const getButton = (data: TimerEventData, idx: number) => {
155+
const getButton = (
156+
data: TimerEventData,
157+
idx: number,
158+
isBigScreen: boolean,
159+
) => {
147160
return data.eventIcon ? (
148161
isBigScreen ? (
149162
<Button
@@ -194,7 +207,7 @@ export const PomodoroTimer = (props: any) => {
194207
{status ? <Status>{status}</Status> : <Status>&nbsp;</Status>}
195208
<TimeRemaining time={time} />
196209
<ButtonGroup variant="pomodoroControl" size="sm" gap="0" isAttached>
197-
{events.map((e, idx) => getButton(e, idx))}
210+
{events.map((e, idx) => getButton(e, idx, isBigScreen))}
198211
</ButtonGroup>
199212
</Stack>
200213
</PopoverContent>

0 commit comments

Comments
 (0)