Probably I'm doing something wrong, I'm very new in react. So, I just need to get the value of a property of the product object.
function Products() {
const [products, setProducts] = useState([]);
useEffect(() => {
api.get('/product/list')
.then(response => {
setProducts((response.data))
})
}, [])
return (
<div className="main">
<div id="landings">
{console.log(products)}
</div>
</div>
);
}
export default Products;
When I use the console.log(products[0])
, I got this:
But, if I try to get a property of the object, like that: console.log(products[0].name)
I got the error
TypeError: Cannot read property 'name' of undefined
What am I doing wrong?