Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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;

 
PREVIOUS NEXT
Tagged: #update #time #react #js
ADD COMMENT
Topic
Name
3+1 =