I have defined a state with array and objects inside as follow.
constructor(props) {
super(props);
this.state = {
posts: [
{
id: '',
assignee_name: '',
assignee_link: ''
}
]
}
}
From the API, it is returning me some data in res which I am not sure how to assign it to the state initiated.
axios.get('http://localhost:3000/api/posts')
.then(res => {
this.setState({
posts: res.data
});
})
I tried following lines
posts.assignee_link: res.data.assignee_link
But this one gives me error.
Can anybody teach me how can I assign it ?