I'm new to React and I'm following a tutotial to learn how to fetch data from a public API.
I can render the "parent" items like the Title in this case, however I can't find a way to render the (nested) child items like Ratings. This is the error I'm getting "TypeError: movie.Ratings is undefined".
Here's the request outcome in JSON:
Here's my React code:
import React, { useEffect, useState } from "react";
import "./App.css";
function App() {
const [movie, getMovie] = useState([]);
useEffect(() => {
const getData = async () => {
const response = await fetch("https://www.omdbapi.com/?apikey=XXXXXXXX&t=Parasite");
const json = await response.json();
getMovie(json);
};
getData();
}, []);
return (
<div className="App">
<ul>
<li>{movie.Title}</li>
{movie.Ratings.map(Score => (
<li>{Score.Source}</li>
))}
</ul>
</div>
);
}
export default App
