so im using GET method here and i want to get the id of the results here is my code :
constructor(props) {
super(props);
this.state = {
CmdCart: [],
id: ""
};
}
componentDidMount() {
fetch("http://10.0.2.2:4000/getcmd", {
method: "GET",
headers: {
'Content-Type': 'application/json'
},
})
.then(res => res.json())
.then(async(results) => {
try {
this.setState({
CmdCart: results
})
console.log("CmdCart", this.state.CmdCart)
this.setState({
id: this.state.CmdCart._id
})
console.log("id", this.state.id)
} catch (e) {
console.log(e)
}
})
}
but it return an undefined value of id , here is my log console :
is there any solution for this ?