Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

86
Views
i cant fetch data after deployment in react app

The app work perfectly locally. The error appears after i deploy it using firebase hosting. The code below is the component where i fetch the data from the api resource

import React, { useEffect, useState } from 'react'
import{ useSelector, useDispatch} from "react-redux"
import { setProducts } from "../containers/redux/actions/productActions"
import ProductComponent from './ProductComponent';
import axios from 'axios';

function ProductList() {
    const products  = useSelector((state) => state);
    const dispatch  = useDispatch()

    const [searchValue, setSearchValue] = useState('');

    const fetchProducts = async ( searchValue) => {
     

        const response = await axios
        .get(`http://www.omdbapi.com/?s=${searchValue}&apikey=??????`)
        .catch((err) => {
            console.log("Err", err);
        });
        if(response.data.Search){
            dispatch(setProducts(response.data.Search));
        }
    };

    useEffect(() => {
        fetchProducts(searchValue);
        // eslint-disable-next-line react-hooks/exhaustive-deps
    },[searchValue]);

    console.log("Products: " , products)
    
    return (
        <div className='home'>
            <div className='search-box'>
                    <input 
                    value={searchValue} onChange={(e) => setSearchValue(e.target.value)} 
                    type="text" 
                    placeholder="Search.." 
                    >        
                    </input>
            </div>
            <div className='products-list'>
            <ProductComponent /> 
            </div>
        </div>
    )
}

export default ProductList

Error message appears on the console of the deployed app :

ProductList.js:21 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'data')

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

   if(response.data.Search){
       dispatch(setProducts(response.data.Search));
   }

Try to check your response first. I think you may have to prove catch error here. Adding else statement in case of response.data.Search is undefined or use response?.data.Search

about 4 years ago · Juan Pablo Isaza Report

0

Most browsers will block insecure requests (http) made from secure sites (https).

Change http://www.omdbapi.com/ to https://www.omdbapi.com/

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!