File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change 11'use client'
22
33import { Clock , Map } from 'lucide-react'
4+ import { useEffect , useState } from 'react'
45import { GrowingUnderline } from '~/components/effects/growing-underline'
56import { Link } from '~/components/ui/link'
67// import { Twemoji } from '~/components/ui/twemoji'
@@ -32,7 +33,16 @@ function getTime() {
3233}
3334
3435export function AddressAndTime ( ) {
35- const { time, diff } = getTime ( )
36+ // NOTE:
37+ // This component depends on the visitor's timezone. If we render it on the server,
38+ // the server timezone will likely differ and cause a hydration mismatch (React #418).
39+ // So we only compute time after the client has mounted.
40+ const [ timeInfo , setTimeInfo ] = useState < { time : string ; diff : string } | null > ( null )
41+
42+ useEffect ( ( ) => {
43+ setTimeInfo ( getTime ( ) )
44+ } , [ ] )
45+
3646 return (
3747 < div className = "space-y-2 py-1.5 text-gray-800 dark:text-gray-200" >
3848 < div className = "flex items-center gap-2" >
@@ -50,7 +60,8 @@ export function AddressAndTime() {
5060 < Clock className = "h-5 w-5" />
5161 < Link href = { TIME_IS } >
5262 < GrowingUnderline className = "font-medium" data-umami-event = "footer-time" >
53- { time } < span className = "text-gray-500 dark:text-gray-400" > ({ diff } )</ span >
63+ { timeInfo ?. time ?? '--:--' } { ' ' }
64+ < span className = "text-gray-500 dark:text-gray-400" > ({ timeInfo ?. diff ?? '...' } )</ span >
5465 </ GrowingUnderline >
5566 </ Link >
5667 </ div >
You can’t perform that action at this time.
0 commit comments