Skip to content

Commit

Permalink
fix(clock): fixed hydration error in clock
Browse files Browse the repository at this point in the history
  • Loading branch information
vildeopp committed Jul 11, 2023
1 parent cb7bb48 commit a3c4d8b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions next-tavla/src/Shared/components/Clock/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { useEffect, useState } from 'react'

function Clock() {
const [currentTime, setCurrentTime] = useState(Date.now())
const [currentTime, setCurrentTime] = useState<number | undefined>(
undefined,
)

useEffect(() => {
setCurrentTime(Date.now())
const intervalId = setInterval(() => setCurrentTime(Date.now()), 1000)
return () => clearInterval(intervalId)
}, [])
Expand All @@ -13,7 +16,7 @@ function Clock() {
timeZone: 'Europe/Oslo',
}).format(currentTime)

return <span>{time}</span>
return <span>{currentTime ? time : 'kunne ikke hente tiden'}</span>
}

export { Clock }

0 comments on commit a3c4d8b

Please sign in to comment.