Getting an error saying `TypeError movies.map is not a function`

import type { GetStaticProps, NextPage } from "next"; import MovieTypes from "../types/MovieTypes"; import MovieCard from "../components/MovieCard"; // type Props = { // movies: MovieTypes[]; // }; const Home = ({ movies }: { movies: MovieTypes | any }) => { return ( <div className="h-screen w-screen flex flex-col"> {movies.map((movie: MovieTypes) => ( <div className="m-24 border p-4 border-lime-600 justify-center" key={movie.id} > <MovieCard movies={movie} /> </div> ))} </div> ); }; export const getStaticProps: GetStaticProps = async () => { const res = await fetch( "https://api.themoviedb.org/3/movie/popular?api_key=KEY" ); const movies = await res.json(); // console.log(results); return { props: { movies, }, }; }; export default Home;
7 Replies
cje
cjeβ€’3y ago
you cant map any
taco is a friend of bluey πŸ‡΅πŸ‡ΈπŸ΄
I'm still getting the errot after removing any
Glorrin
Glorrinβ€’3y ago
const Home = ({ movies }: { movies: MovieTypes | any }) should probably be { movies }: { movies: MovieTypes[] } Also are you sure your api return a list ? And not an object containing page, results, and results would be your list ?
taco is a friend of bluey πŸ‡΅πŸ‡ΈπŸ΄
It works now, thank you! Wait no it still gives me that error on the page.
.hatulapro
.hatulaproβ€’3y ago
Did you make sure to pass the props to your component? In _app.tsx you should have something like this:
<Component {...props} />
<Component {...props} />
taco is a friend of bluey πŸ‡΅πŸ‡ΈπŸ΄
Yes and I am still getting "movies .map is not a function"
Scot
Scotβ€’3y ago
What is the type of movies at runtime
Want results from more Discord servers?
Add your server