What is the exact functionality of Search (Data.Search) function in the Code is it built-in funnction to search in Json?

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(() => {


  }, []);

  const searchMovies = async (title) => {

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

    const data = await response.json();


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

>Solution :

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)

Leave a Reply