1.01K viewsMern Amazona
0 Comments

best regards

my code HomeScreen.js is :

import { useEffect, useState } from ‘react’;
import { Link } from ‘react-router-dom’;
import axios from ‘axios’;
// import data from ‘../data’;

function HomeScreen() {

const [producto, setProducts] = useState([]);
useEffect(() => {
const fetchData = async () => {
const result = await axios.get(‘/api/products’);
setProducts(result.data);
};
fetchData();
}, []);
return (

Featured Products

{producto.map((product) => (

{product.name}

${product.price}

Add to cart

))}

);
}
export default HomeScreen;

thanks

Bassir Changed status to publish November 26, 2023

hello there,

the issue is here:

const result = await axios.get(‘/api/products’);

the result is not an array. console.log(result) to see what you get from backend.

Bassir Answered question October 14, 2022