I have an array of objects (language codes and names) that I am trying to spread into another array in local state in a react component. The structure of the array I am trying to spread is like this:
let langs = [
{code: "af", name: "Afrikaans"},
{code: "sq", name: "Albanian"}
]
I am trying something simply like this:
this.setState({
languages: [...langs]
},
console.log(this.state.languages);
);
When I try to console.log languages in the callback from setState the array is empty. What am doing wrong here?