I am doing my front in react and I am consuming microservices from laravel, there is one that the only thing it does is return a json with a list of countries, but I cannot do a cycle to access the object, I have used map and for, but nothing It works, as the microservice returns a plain text json, I first pass it through JSON.parse to create an object, and that object looks like this:
object after JSON.parse of response microservice
Here is my code of how I request using axios:
class MisDatosEmprendedor extends React.Component {
constructor(props){
super(props);
this.state = {
country:'',
}
}
async componentDidMount() {
await axios({
url: `${countryUrl}`,
method: 'GET',
})
.then(response =>{
var objson = JSON.parse(response.data);
this.setState({
country: objson,
})
})
.catch(error => {
console.log(error)
return error;
});
}
}
Now I try to use map to loop the render and show all countries in a select, but it tells me this.state.country.countries not defined error
render(){
return <React.Fragment>
{this.state.country.countries.map(function(d){
return(
<option value={d.id}>{d.name}</option>
)
})}
</React.Fragment>
}