basir / amazona

Build Ecommerce Like Amazon By MERN Stack
https://www.udemy.com/course/build-ecommerce-website-like-amazon-react-node-mongodb
597 stars 483 forks source link

TypeError: products.map is not a function #69

Open gitwithsarthak opened 3 years ago

gitwithsarthak commented 3 years ago

facing these issues at the homeScreen.js

`import React, { useEffect, useState } from 'react'; import axios from 'axios'; import Product from '../components/Product'; import LoadingBox from '../components/LoadingBox'; import MessageBox from '../components/MessageBox';

export default function HomeScreen() { const [products, setProducts] = useState([]); const [loading, setLoading] = useState(false); const [error, setError] = useState(false); useEffect(() => { const fecthData = async () => { try { setLoading(true); const { data } = await axios.get('/api/products'); setLoading(false); setProducts(data); } catch (err) { setError(err.message); setLoading(false); } }; fecthData(); }, []); return (

{ loading ? ( ) : error ? ( {error} ) : (
{products && products.map((product) => ( ))}
)}

); } `

Mjeanbapti commented 3 years ago

Im getting the same error.