我遇到了一个错误:“无法读取未定义的 'map' 属性”,因为电影列表“movies”是未定义的。您能看出我在哪里出了问题吗?非常感谢。
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