146
rated 0 times
[
153]
[
7]
/ answers: 1 / hits: 23038
/ 6 Years ago, fri, july 6, 2018, 12:00:00
I am learning React.js and trying to fetch API like this
constructor() {
super();
this.state = {person: []};
}
componentDidMount() {
fetch('https://randomuser.me/api/?results=500', {mode: 'no-cors'})
.then(results => {
return results.json();
})
.then(data => {
let person = (data.results || []).map((pic) => {
return(
<div key={pic.results}></div>
)
})
this.setState({person: person});
console.log(state, this.state.person);
})
}
render() {
return (
<div>
{this.state.person}
</div>
);
}
and this is the error I get
I am pretty new in this, so if anyone can help me with this that would be great. Thanks
More From » reactjs