2
I made a request in a URL via Fetch, however it returns me an error when I ask for the mapping of the json, someone knows how to solve ?
I’ve hidden the URL because it’s private.
import React, { Component } from 'react';
class App extends Component {
constructor(props){
super(props);
this.state = {
items:[],
isLoaded: false,
}
}
componentDidMount(){
fetch('***')
.then(res => res.json())
.then(json => {
this.setState({
isLoaded: true,
items : json,
})
});
}
render() {
var{isLoaded, items} = this.state;
if(!isLoaded){
return <div>Loading..</div>
}
else{
return (
<div className="App">
<ul>
{items.map(item => (
<li key = {item.id}>
Name : {item.name} | {item.name}
</li>
))};
</ul>
</div>
);
}
}
}
export default App;
Apparently it does not recognize items as an array
– Lucas Brogni
On the return of his call ". then(res => res.json()) ", try placing a console.log() and checking what is returning from the api because as Lucas Brogni quoted it may be that the api is not returning an array ....
– Sóstenes G. de Souza