1import React, { useState } from 'react'
2
3const Clock = ({ theme }) => {
4 // For digital clock
5 let time = new Date().toLocaleTimeString();
6 let [ctime, setCTime] = useState();
7 const updateTime = () => {
8 time = new Date().toLocaleTimeString();
9 setCTime(time);
10 }
11 setInterval(updateTime, 1000);
12 return (
13 <>
14 <h2> {ctime}.</h2>
15 </>);
16}
17export default Clock;
18
19
1import React, { useState } from 'react'
2
3const Clock = () => {
4 const [time, setTime] = useState('');
5 setTimeout(() => {
6 setInterval(() => {
7 setTime(new Date().toLocaleTimeString())
8 }, 1000)
9 })
10 return (
11 <div>
12 <h1>Hello, world!</h1>
13 <h2>It is {new Date().toLocaleTimeString()}.</h2>
14 </div>);
15}
16export default Clock;