-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathProductImage.tsx
More file actions
36 lines (28 loc) · 792 Bytes
/
ProductImage.tsx
File metadata and controls
36 lines (28 loc) · 792 Bytes
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
import { useContext } from 'react';
import { ProductContext } from './ProductCard';
import styles from '../styles/styles.module.css'
import noImage from '../assets/no-image.jpg';
export interface Props {
img?: string;
className?: string;
style?: React.CSSProperties
}
export const ProductImage = ({ img, className, style }: Props ) => {
const { product } = useContext( ProductContext );
let imgToShow: string;
if ( img ) {
imgToShow = img;
} else if ( product.img ) {
imgToShow = product.img
} else {
imgToShow = noImage;
}
return (
<img
className={ `${ styles.productImg } ${ className }` }
src={ imgToShow }
style={ style }
alt="Product"
/>
);
}