🧠 React Interview Question | useEffect & State What will this React code log after the 𝐢𝐧𝐢𝐭𝐢𝐚𝐥 𝐫𝐞𝐧𝐝𝐞𝐫? 🤔 This is a classic 𝐮𝐬𝐞𝐄𝐟𝐟𝐞𝐜𝐭 + 𝐝𝐞𝐩𝐞𝐧𝐝𝐞𝐧𝐜𝐲 array question that often appears in: - React interviews - Machine coding rounds - Frontend assessments 💡 Understanding 𝐰𝐡𝐞𝐧 𝐮𝐬𝐞𝐄𝐟𝐟𝐞𝐜𝐭 𝐫𝐮𝐧𝐬 and 𝐡𝐨𝐰 𝐬𝐭𝐚𝐭𝐞 𝐮𝐩𝐝𝐚𝐭𝐞𝐬 trigger effects is more important than memorizing syntax. 👉 Look at the dependency array carefully. 👉 Think about the initial render vs button click. Drop your answer in the comments 👇 𝐀) 𝟎 𝐁) 𝟏 𝐂) 𝟐 𝐃) 𝐍𝐨𝐭𝐡𝐢𝐧𝐠 I’ll share the explanation in the comments 🔍 #reactjs #javascript #frontenddeveloper #webdevelopment #codinginterview #reacthooks #useeffect #codingquestions #softwaredeveloper #learnreact #developers #techinterviews
0 initially
0 As use effect will print 0 initially
Initially it will print 0 .because the use effect will render and the count we have set in the usestate is 0 so it will print 0.
0 and if you click on button output will be 1
answer: 0 If you click the button once then it would log 1 😉
It log 0 due to initial state
The initial will be 0 but when click the button the count will be 1
initial render 0
b
-1, it's Sunday, I am not in mood, sorry.