I have this Api call, which returns my contact list, and is supposed to save them as an array of objects into this.state.contacts, so that I can of course reference them in other places.
The line that says console.log(result) logs exactly what I expect... which is an array of objects containing all of my contact list data.
But after that, the console.log(Contacts: ${this.state.contacts} logs instead of the same data in result:
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[obj
class Database extends Component {
constructor(props){
super(props);
this.state = {
clients: [],
contacts: []
}
}
componentDidMount() {
fetch(API_URL + `/contacts/all`)
.then(res => {
if (!res.ok) {
throw new Error();
}
return res.json();
})
.then((result) => {
this.setState({ contacts: result });
console.log(result);
console.log(`Contacts: ${this.state.contacts}`);
})
.catch(error => {
console.log(error);
})
);
}
What am I missing here? I feel like I've done it like this before and it worked fine.