I am new to react-native and I am here trying to update the state when the component is loaded. however the state is not updating.
constructor(props) {
super(props);
this.state = {
selectedSection: 'None',
sectionObject: { index: 0, key: ''},
sectionIndex: 0,
sectionArray: [],
};
}
componentDidMount()
{
this.setState({
sectionObject: { index: this.state.sectionIndex, key: this.state.selectedSection},
sectionArray: this.state.sectionArray.concat(this.state.sectionObject),
})
console.log('sectionObject:',this.state.sectionObject);
console.log('section array:',this.state.sectionArray);
}
What am I doing wrong here?