Skip to content

Commit

Permalink
created two more Comps to store cart data
Browse files Browse the repository at this point in the history
  • Loading branch information
HMP1993 committed Jan 2, 2023
1 parent 1819333 commit 41704cb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import "./App.css";
import Header from "./components/Layout/Header";
import { Fragment, useState } from "react";
import { useState } from "react";
import Meals from "./components/Meals/Meals";
import Cart from "./components/Cart/Cart";
import CartProvider from "./store/CartProvider";

function App() {
const [cartIsShown, setCartIsShown] = useState(false);
Expand All @@ -13,13 +14,13 @@ function App() {
setCartIsShown(false);
};
return (
<Fragment>
<CartProvider>
{cartIsShown && <Cart onHideCart={hideCartHandler} />}
<Header onShowCart={showCartHandler} />
<main>
<Meals />
</main>
</Fragment>
</CartProvider>
);
}

Expand Down
18 changes: 18 additions & 0 deletions src/store/CartProvider.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from "react";
import CartContext from "./cart-context";

const CartProvider = (props) => {
const addItemToCartHandler = (item) => {};
const removeItemFromCarthandler = (id) => {};

const cartContext = {
items: [],
totalAmount: 0,
addItem: addItemToCartHandler,
removeItem: removeItemFromCarthandler,
};

return <CartContext.Provider value={cartContext} >{props.children}</CartContext.Provider>;
};

export default CartProvider;
10 changes: 10 additions & 0 deletions src/store/cart-context.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from "react";

const CartContext = React.createContext({
items: [],
totalAmount: 0,
addItem: (item) => {},
removeItem: (id) => {},
});

export default CartContext;

0 comments on commit 41704cb

Please sign in to comment.