-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathProductCard.tsx
53 lines (43 loc) · 1.35 KB
/
ProductCard.tsx
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
42
43
44
45
46
47
48
49
50
51
52
53
import styles from "../styles/styles.module.css";
import { useProducts } from "../hooks/useProduct";
import { ReactElement, createContext } from "react";
import {
Product,
ProductContextProps,
onChangeArg,
} from "../interfaces/interfaces";
export interface Props {
product: Product;
value?: number;
children?: ReactElement | ReactElement[];
className?: string;
style?: React.CSSProperties;
onChange?: (args: onChangeArg) => void;
}
export const ProductContext = createContext({} as ProductContextProps);
export const { Provider } = ProductContext;
export const ProductCard = ({
children,
product,
className,
style,
onChange,
value
}: Props) => {
const { counter, increaseBy } = useProducts({ product, onChange, value});
return (
<Provider value={{ counter, increaseBy, product }}>
<div style={style} className={`${styles.productCard} ${className}`}>
{children}
{/* esto se renderisa super bien y se llama Component patter */}
{/* <ProductImage img={product.img} /> */}
{/* <ProductTitle title="Cofie" /> */}
{/* <img src={NoImg} alt="No Imagen" /> */}
{/* <ProductButtons counter={counter} increaseBy={increaseBy} /> */}
</div>
</Provider>
);
};
// ProductCard.Title = ProductTitle;
// ProductCard.Image = ProductImage;
// ProductCard.Buttons = ProductButtons;