I am having a problem of updating a state array variable. I have looked fro many resources but none was worked.
I have Updated the code to view the full architecture of how the methods are linked to one another
This is how i defined the array in the state initially.
constructor(props) {
super(props);
this.state = {
test:[]
}
}
This is the render method. inside render method i have called to getQuizView() method
render(){
return (
<div>
{this.getQuizView()}
</div>
)
}
and inside getQuizView() method i have called to my updateArray() method
getQuizView(){
return (
<div>
{this.updateArray()}
</div>
)
}
The following method (updateArray()) is used to update the state variable.
updateArray(){
for(var i=0; i<this.props.questions.length;i++){
this.setState({ test: [...this.state.test, {id: this.props.questions[i].questionId, active: '0'}] })
}
}
But it seems like setState is happening infinitely. but this.props.questions.length = 34

this.props.questions?