what is Data.search here

import React, { useState, useEffect } from "react";

import MovieCard from "./MovieCard";

import SearchIcon from "./search.svg";

import "./App.css";

const API_URL = "http://www.omdbapi.com?apikey=b6003d8a";

const App = () => {

  const [searchTerm, setSearchTerm] = useState("");

  const [movies, setMovies] = useState([]);

  useEffect(() => {

    searchMovies("Batman");

  }, []);

  const searchMovies = async (title) => {

    const response = await fetch(`${API_URL}&s=${title}`);

    const data = await response.json();
    
    setMovies(data.Search);

    
  };


why don't we write simply setMovies(data);

1

There are 1 answers

0
Y U K I M U R A On BEST ANSWER

no, it is not. you are fetching data from an api and it returns an object, which has a value called search, therefore you are setting data.search value as your movies, not entire object returned from the api, you can check this easily by logging both fields, like so :

const data = await response.json();
   console.log('this is data' , data)
   console.log('this is data.search', data.search)
setMovies(data.Search);