我收到错误消息“无法读取未定义的属性'map'”,但无法弄清原因-地图未起作用,因为“电影”未定义。你能看到我做错了吗?非常感谢。
const Dashboard = () => {
const discoverUrl = 'https://movied.herokuapp.com/discover';
const [movieList, setMovies] = useState({ movies: [] });
useEffect(() => {
const getAllMovies = () => {
fetch(discoverUrl)
.then(response => response.json())
.then(data => setMovies(data))
}
getAllMovies()
}, [])
return (
<ul>
{movieList.movies.map(movie => (
<li>
<p>{movie}</p>
</li>
))}
</ul>
);
}
export default Dashboard```
TypeError: Cannot read property 'map' of undefined
Run Code Online (Sandbox Code Playgroud)