@@ -21,7 +21,7 @@ import { Select, type SingleValue } from "chakra-react-select";
2121import dayjs from "dayjs" ;
2222import timezone from "dayjs/plugin/timezone" ;
2323import utc from "dayjs/plugin/utc" ;
24- import React , { useMemo } from "react" ;
24+ import React , { useEffect , useMemo , useState } from "react" ;
2525
2626import { useTimezone } from "src/context/timezone" ;
2727import type { Option as TimezoneOption } from "src/utils/option" ;
@@ -31,6 +31,7 @@ dayjs.extend(timezone);
3131
3232const TimezoneSelector : React . FC = ( ) => {
3333 const { selectedTimezone, setSelectedTimezone } = useTimezone ( ) ;
34+ const [ currentTime , setCurrentTime ] = useState < string > ( "" ) ;
3435 const timezones = useMemo < Array < string > > ( ( ) => {
3536 const tzList = Intl . supportedValuesOf ( "timeZone" ) ;
3637 const guessedTz = dayjs . tz . guess ( ) ;
@@ -54,7 +55,17 @@ const TimezoneSelector: React.FC = () => {
5455 }
5556 } ;
5657
57- const currentTime = dayjs ( ) . tz ( selectedTimezone ) . format ( "YYYY-MM-DD HH:mm:ss" ) ;
58+ useEffect ( ( ) => {
59+ const updateTime = ( ) => {
60+ setCurrentTime ( dayjs ( ) . tz ( selectedTimezone ) . format ( "YYYY-MM-DD HH:mm:ss" ) ) ;
61+ } ;
62+
63+ updateTime ( ) ;
64+
65+ const interval = setInterval ( updateTime , 1000 ) ;
66+
67+ return ( ) => clearInterval ( interval ) ;
68+ } , [ selectedTimezone ] ) ;
5869
5970 return (
6071 < VStack align = "stretch" gap = { 6 } >
0 commit comments