I have this state which is nested and I am having difficulty in setting state. Error:undefined is not an object (evaluating this.state.form) My initial state is :
this.state={
activePage:0,
visible:false,
questionType:null,
form:{
title:'',
description:'',
pages:[{
title:'',
description:'',
questions:[
]
}]
}
};
Now every time a user clicks, I need to add more object to pages array which should be having a title (''), description ('') and questions (empty list). I tried achieving this but it doesn't seem to be working.
let newForm={
...this.state,
form:{
...this.state.form,
pages:[
...this.state.form.pages,
pageData
]
}
};
console.log('newForm',newForm);
this.setState({
form:newForm
});
This is how my pageData looks like
let pageData={
title:'',
description:'',
questions:[]
};