/
Products.jsx
executable file
·41 lines (34 loc) · 1.47 KB
/
Products.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import React, { Component } from 'react';
import { Link } from "react-router-dom";
import classes from './Products.module.css';
import { myContext } from '../../cartContext';
class Products extends Component {
static contextType = myContext;
componentDidUpdate() {
console.log('Products context: ', this.context);
}
render() {
if ( this.context.state.storeProducts.length > 0 ) {
const products = this.context.state.storeProducts.map(product => {
return (
<div key={product.id} className={classes.productCard} product={product}>
<div className="productImage">
<Link to={{
pathname: `/product/${product.id}`,
state: { product: {...product} }
}}>
<img className={classes.productImg} src={product.images[0].src} alt={product.images[0].name} width="200" />
</Link>
</div>
<div className="productName">{product.name}</div>
<div className="productPrice">{product.price}€</div>
</div>
)
});
return <div className={classes.productsList}>{products}</div>;
} else {
return 'Loading...';
}
}
}
export default Products;