Since i'm new to react, i've worked little with react states. It is all fine when updating a simple state but the problems occurs when updating a state containing an array of objects. I've found some related answers on stackoverflow and other sites but still unable to find a better solution for the problem.
Initial states:
this.state = {
article: [{
title: '',
category: '',
author: '',
desc: '',
date: ''
},
{
authorName: '',
profile: '',
joinedOn: ''
}]
}
Updating states:
<input type="text" name="title" placeholder="Enter article title" className="form-control" onChange={e => this.setState({article: [...this.state.article, {title: e.target.value}]})} />
Accessing states:
console.log(this.state.article[0].title)
Console is showing empty string.