fix: update seconds lamp every second when using system time
This commit is contained in:
committed by
Loic Coenen (aider)
parent
0b3a1d4d66
commit
abf8b13fc7
@@ -1,4 +1,4 @@
|
||||
import { useState } from "react";
|
||||
import { useState, useEffect } from "react";
|
||||
import { BerlinClock } from "./BerlinClock";
|
||||
import { DigitalClock } from "./DigitalClock";
|
||||
import { useCurrentTime } from "../hooks/useCurrentTime";
|
||||
@@ -9,6 +9,14 @@ export function TimeConverter() {
|
||||
const [useSystemTime, setUseSystemTime] = useState(false);
|
||||
const berlinClock = dateToBerlin(currentTime);
|
||||
|
||||
useEffect(() => {
|
||||
if (!useSystemTime) return;
|
||||
const id = setInterval(() => {
|
||||
setCurrentTime(new Date());
|
||||
}, 1000);
|
||||
return () => clearInterval(id);
|
||||
}, [useSystemTime, setCurrentTime]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<label>
|
||||
|
||||
Reference in New Issue
Block a user