Answers for "how can we update time in react js"

0

how can we update time in react js

import React, { useState, useEffect } from "react";
import "./App.css";
const App = () => {
  let time = new Date().toLocaleString();
  const [cTime, setTime] = useState(time);
  useEffect(() => {
    setInterval(() => {
      setTime(time);
    }, 1000);
  });
  return (
    <div className="App">
      <div className="clock-container">
        <h3 className="digitalClock">digital clock</h3>
        <div className="time-container">{cTime}</div>
      </div>
    </div>
  );
};

export default App;
Posted by: Guest on October-26-2021

Code answers related to "how can we update time in react js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language