am having a problem understanding react state . i am pushing an object on click of a button taking multiple values from input fields into array . onClick of button should show the latest state but its showing the previous input values from the form. how could i resolve this issue .
let addToList = ()=>{
let data={};
data.component=returnCmpName(SelCom);
data.question=question;
switch(SelCom){
case 1 : case 2:
data.required=checked;
data.errorMessage=errorMessage;
break;
case 3 : case 4 : case 5: data.options=NewList.slice(); break;
case 6:
data.fileAllowed=fileAllowed;
data.fileLimit=fileLimit;
break;
case 7: break;
case 8: break;
default:break;
}
rendcompState(prevData=>[data,...prevData])
console.log(rendComp)
}