Perbarui waktu terakhir yang diperbarui bereaksi JS

import React, { useState, useEffect } from "react";

// store your time variable(dt) in state
const [dt, setDt] = useState(new Date().toLocaleString());

// setup a useEffect with a setInterval that rewrites dt to state (using setDt) every 1 second
useEffect(() => {
    let secTimer = setInterval( () => {
      setDt(new Date().toLocaleString())
    },1000)

    return () => clearInterval(secTimer);
}, []);
Anxious Alligator