componentDidMount() {
$.ajax({
type: 'post',
url: 'requests.php',
data: {requestKey: "hello"}
}).done(function(data){
this.setState({
items: data
});
}.bind(this));
}
render(){
let items = this.state.items;
console.log(items);
return(
<div id="tops">
<h1 className="header">
What's top!
<a href="#" className="more">more!</a>
</h1>
{items.map(function(item){
return(
<TopsItem
img={item.img}
heading={item.heading}
desc={item.desc}
/>
);
})}
</div>
);
}
The data in state.items does not effect the components in map function. And yet I get this error:
items.map is not a function
console.log(items); works after 1sec.
At first it's empty, then it gets the data in it.
items && items.mapwill work