0

I'm attempting to develop a modest film-based project. I have used TMDB Movies to obtain movies. I don't sure where I went wrong because the data in my console is displaying OK, but when I try to map and display that element, I receive an error saying:

"Movies.map is not a function."

Please try to correct my mistake.

enter image description here

import "./App.css";
import MemsData from "./Components/MemsData";
import NewMemsData from "./Components/NewMemsData";
import FilterElement from "./Components/FilterElement";
import MovieBox from "./Components/MovieBox";
import { useEffect, useState } from "react";
import Axios from "axios";

function App() {
  const API_URL =
    "https://api.themoviedb.org/3/movie/popular?api_key=8f11538792fbc26efa63aa919f0844b8";

  const [movie, setMovie] = useState([]);

  useEffect(() => {
    Axios.get(API_URL).then((res) => {
      console.log(res);
      setMovie(res.data);
    });
  });

  return (
    <div className="App">
      <h2>Movie Api</h2>
      {
        movie.map((moviereq, index) => {
          return <div key={index}>{moviereq.title}</div>;
        })}
    </div>
  );
}

export default App;
2
  • The error specifically says that Movies.map is not a function, instead of movie.map? Where in the code is there a Movies.map used? Commented Dec 21, 2022 at 12:15
  • In any event... If something.map is not a function then something is not an array. So what is it? In your debugging, what is the exact value of something when the error occurs? What did you expect the value to be and why? Commented Dec 21, 2022 at 12:16

1 Answer 1

1

You need to go one deeper and access results: setMovie(res.data.results);

Codesandbox link: https://codesandbox.io/s/frosty-voice-hc912d?file=/src/App.js:392-400

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.