Reactjs Counter Component Logs Initial State

This confused me for a while 😅 Can you tell what this will print? 👇 import { useEffect, useState } from "react"; export default function Counter() { const [count, setCount] = useState(0); useEffect(() => { setInterval(() => { console.log(count); }, 1000); }, []); return ( <button onClick={() => setCount(count + 1)}> Count: {count} </button> ); } After clicking the button a few times… what do you think gets logged every second? Curious to see your answers .. #Reactjs #javascript #frontenddev

0,0,0 As dependency array is empty count reference is 0

To view or add a comment, sign in

Explore content categories