Tell us what’s happening:
Hello Developers,
I’m trying to finish my Random Quote Machine. I build a small React App and I’m using the fetch method for calling an API that allows me to access to random quotes. Unfortunately, It doesn’t work. I tried to test the API with Postman and if I use the API though internet it actually works. How is possible?
PS the page stay with the
Your code so far
class App extends Component {
constructor(props){
super(props);
this.state = {
items: [],
isLoaded: false,
}
}
componentDidMount() {
fetch('https://jsonplaceholder.typicode.com/users')
.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}
</li>
))};
</ul>
</div>
);
};
}
}
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36
.