React.js: Не обработанный отказ (TypeError): Cannot read property 'error' of undefined
hello я просто получаю ошибку "Unhandled Rejection (TypeError): Cannot read property 'error' of undefined " и это мой Home.js
import React ,{useState, useEffect} from 'react'
import {GetProducts} from '../core/helper/coreapicalls'
export default function Home() {
const [Products , setProducts] = useState([]);
const [Error , setError] = useState(false);
const LoadAllProducts = ()=>{
GetProducts()
.then(data =>{
if(data.error){
setError(data.error);
console.log(Error)
}
setProducts(data);
})
}
useEffect(()=>{
LoadAllProducts()
},[]);
return (
<div>
<h1>Home Component</h1>
<div className="row">
{Products.map((product,i)=>{
return(
<div key = {i}>
<h1>{product.name}</h1>
</div>
)
})}
</div>
</div>
)
}
а это код получения API
import {API} from '../../backend';
export const GetProducts = ()=>{
return fetch(`${API}product`,{method : "GET"})
.then(response =>{
return response.json();
})
.catch(error=>{
console.log(error);
});
};
API - это просто переменная окружения, устанавливающая ссылку api : localhost:8000/api/