skip to Main Content

Why is my console not printing the message after every minute passed, does useEffect hook runs only once? – Reactjs

import React, { useState, useEffect } from 'react'; function DigitalClock() { const[currentTime, setCurrentTime] = useState(new Date()); useEffect(()=>{ const interval = setInterval(()=>{ setCurrentTime(new Date()); },1000); return () => clearInterval(interval); },[]); useEffect(()=>{ const second = currentTime.getSeconds(); if(second===0){ console.log("another minute passed"); } },[currentTime])…

VIEW QUESTION
Back To Top
Search