I am building a simple react app that is meant to pass several functions responsible to update the same state object in the parent component, but for some reason, only one of two functions gets executed when triggered by an onClick event in a children component or at least so it seems, let me show you some code:
Children component:
<button id='but2' onClick={()=>{
props.isBeginner(true);
props.nextStep(2)
}}
className={classes.chooseButton} >Choice number 1</button>
Parent component functions:
isBeginner(b){
setUser({...user,first_timer:b})}
nextStep =(step)=>{
setUser({...user,setup_step:step})}
Between the children and the parent components, there is a middle component responsible to sort the right child component to render, it does that through a switch operator:
switch(step){
case 1 :{return <StepOne user={props.user} nextStep={props.nextStep}
isBeginner={props.isBeginner} />};
break;
case 2 :{return <StepTwo whatMedium={props.whatMedium} user=
{props.user} nextStep={props.nextStep}/>}
break;
case 3 :{return <StepThree user={props.user} nextStep=
{props.nextStep}/>}
break;
case 4 :{return <StepFourth nextStep={props.nextStep}/>}
break;
default:{<StepOne isBeginner={props.isBeginner} nextStep={
props.nextStep}/>}
}
Why can't I update the state of the parent component using two different functions (passed down to children components) to update different values of the same (state) object?