Seeking guidance on parsing data obtained from an axios.get request to the TMDB-API, a movie database.
Here is a simplified version of the JSON structure returned by the API:
{
data: {
results: [
{
name: 'Free Guy'
poster_path: "/yc2IfL701hGkNHRgzmF4C6VKO14.jpg"
},
{
name: 'Squid Game'
poster_path: "/uu4TgyyW259aOZHN0Ew4TEfjnUG.jpg"
},
]
}
}
My state is defined as follows:
interface MovieType {
name: string
poster_path: string
}
const [movies, setMovies] = useState<MovieType[] | []>([]);
However, when attempting to retrieve and set the results from the get-request, I encounter the TypeScript error:
Property 'results' does not exist on type 'DataMovieType'.ts(2339)
interface DataMovieType {
data: {
results: MovieType[]
}
}
const request = await axiosInstance.get<DataMovieType>(fetchUrl);
setMovies(request.data.results);
I have explored alternative interfaces for DataMovieType but have not found a solution yet.
If you need more information or have any insights, please let me know. Appreciate your help!
Thank you, [name]