I have an api with the following data
[
{ "title": "The Godfather", "year": 1972, "rating": 9.2, "tmdb_id": 238 },
{ "title": "Fight Club", "year": 1999, "rating": 8.8, "tmdb_id": 550 },
...
]
I am using getserverside props to fetch this data.
export const getServerSideProps: GetServerSideProps = async () => {
const res = await fetch("http://localhost:3000/api/movies")
const movies = await res.json()
return { props: {
movies
}}
}
I use the following type to define movies
type Data = {
title: string,
year: number,
rating: number,
tmdb_id: number
}
const Home = ({ movies }: Array<Data>) => {...
When i map this data using {movies.map((movie: Data)=> { NextJS throws the following error
Type error: Property 'movies' does not exist on type 'Data[]'.
> 11 | const Home = ({ movies }: Array<Data>) => {
| ^