Answers for "clock reactjs"

1

clock reactjs

import React, { useState } from 'react'

const Clock = ({ theme }) => {
	// For digital clock
	let time = new Date().toLocaleTimeString();
	let [ctime, setCTime] = useState();
	const updateTime = () => {
		time = new Date().toLocaleTimeString();
		setCTime(time);
	}
	setInterval(updateTime, 1000);
	return (
		<>
        <h2> {ctime}.</h2>
		</>);
}
export default Clock;
Posted by: Guest on May-15-2021
0

clock reactjs

import React, { useState } from 'react'

const Clock = () => {
    const [time, setTime] = useState('');
    setTimeout(() => {
        setInterval(() => {
            setTime(new Date().toLocaleTimeString())
        }, 1000)
    })
    return (
        <div>
            <h1>Hello, world!</h1>
            <h2>It is {new Date().toLocaleTimeString()}.</h2>
        </div>);
}
export default Clock;
Posted by: Guest on May-13-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language