I am using react to try to populate data on render during a fetch call but am running into a problem. When trying to run a regular fetch api call using placeholder information everything works just fine. However, when trying to get the "weather" or main sections of data to populate I am having a problem. The specific error I am receiving is "uncaught TypeError: this.state.posts.map is not a function"
import logo from './logo.svg';
import './App.css';
import React from 'react';
class App extends React.Component {
state = {
posts: [],
};
componentDidMount() {
fetch("https://mm214.com/demo.php")
.then(response => response.json())
.then(posts => {console.log(posts)
this.setState({ posts });
}
)
.catch(error => console.error(error));
}
render() {
return (
<header>
<h1>Weather</h1>
<li>
{this.state.posts.map(post => (
<li key={post}>{post.main} {post.temp}</li>
)
)
}
</li>
</header>
);
}
}
export default App;