import React,{useState,useEffect} from 'react'
function Counter() {
const [count,setCount] = useState(0)
const incCount=()=>{
console.log("count ",count)
// setCount(count+1)
setCount(x=>x+1)
}
useEffect(()=>{
console.log('use effect called')
const intervalId = setInterval(()=>
incCount(),1000)
return()=>{
// clearInterval(intervalId);
console.log("clear interval called")
}
},[])
return (
<div>
{count}
</div>
)
}
export default Counter
In display count is increasing as expected but in console every time it shows 0 only
incCount is excuting after every one second and in console count 0 is printing is whereas on screen count is increasing by 1 every time as expected