I have two state variable that I update them in func function . we know every render in component has own setTimeout . so when I write text fast in input ، I expect that result of number state be 1 once . Its result is 1 but it log twice in console . why?
export default function Mycomponent() {
const [number,setnumber] =useState(0);
const [string,setstring] =useState('');
function func(event){
setstring(event.target.value);
setTimeout(()=>{
setnumber(number+1);
},3000);
// 1_ every render has own setTimeout so when I write text fast in input I expect that result of number be 1 once .
// its result is 1 but it log twice in console. why ???
}
console.log(number,string);
return (
<>
<input type='text'onChange={(e)=>{func(e)}} value={string}/>
</>
)
}