From 42de00bbae609f6aa38fefb9820cd62cb1f2bc5d Mon Sep 17 00:00:00 2001 From: mohammadpy8 Date: Sat, 26 Aug 2023 21:01:24 +0330 Subject: [PATCH] cartcontext --- src/context/CartContextProvider.tsx | 43 +++++++++++++++++++++++++++++ src/types/products.types.ts | 12 ++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/context/CartContextProvider.tsx create mode 100644 src/types/products.types.ts diff --git a/src/context/CartContextProvider.tsx b/src/context/CartContextProvider.tsx new file mode 100644 index 0000000..da1ae12 --- /dev/null +++ b/src/context/CartContextProvider.tsx @@ -0,0 +1,43 @@ +import React, { createContext, useState } from 'react'; + +import { Produts } from '../types/products.types'; + +type CartContextType = { + userCart: Produts[]; + addProduts: (id: number) => void; + removeProduts: (id: number) => void; + removeAll: () => void; + shop: Produts[]; +}; + +type CartProps = { + children: React.ReactNode; +}; + +export const CartContext = createContext({} as CartContextType); + +const CartContextProvider = ({ children }: CartProps) => { + + const [userCart, setUserCart] = useState([]); + const [shop, setShop] = useState([]); + + const addProduts = (id: number) => { + + }; + + const removeProduts = (id: number) => { + + }; + + const removeAll = () => { + + }; + + return ( + + {children} + + ); +}; + +export default CartContextProvider; \ No newline at end of file diff --git a/src/types/products.types.ts b/src/types/products.types.ts new file mode 100644 index 0000000..101290c --- /dev/null +++ b/src/types/products.types.ts @@ -0,0 +1,12 @@ +export type Produts = { + id: number; + title: string; + price: number; + description: string; + category: string; + image: string; + rating: { + rate: number; + count: number; + } +}; \ No newline at end of file