I have some question in react. It's not a big problem, but I don't understand.
I make a components where new data is continuously added to data. It makes sense that two console logs appear at first. Because of Mount and Update. But next cycle, here is my question.Why do 4 console logs appear? and then 8.. and then 16.. and then 32 .......
here is the code.
import React, { useState } from 'react'
const Ex = () => {
const [state, setstate] = useState({ test: 'data' })
const handleDate = () => {
const { test } = state
const data = 'new data'
setstate({ test: test + data })
console.log(`test: ${test}`);
}
setTimeout(handleDate, 3000);
return (
<div>
<span>Result: {state.test}</span>
</div>
)
}
export default Ex