Skip to content

Commit

Permalink
cartcontext
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadpy8 committed Aug 26, 2023
1 parent 9372096 commit 42de00b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/context/CartContextProvider.tsx
Original file line number Diff line number Diff line change
@@ -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<Produts[]>([]);
const [shop, setShop] = useState<Produts[]>([]);

const addProduts = (id: number) => {

};

const removeProduts = (id: number) => {

};

const removeAll = () => {

};

return (
<CartContext.Provider value={{removeAll, addProduts, removeProduts,shop, userCart }}>
{children}
</CartContext.Provider>
);
};

export default CartContextProvider;
12 changes: 12 additions & 0 deletions src/types/products.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export type Produts = {
id: number;
title: string;
price: number;
description: string;
category: string;
image: string;
rating: {
rate: number;
count: number;
}
};

0 comments on commit 42de00b

Please sign in to comment.