Skip to content

Commit

Permalink
components composition
Browse files Browse the repository at this point in the history
  • Loading branch information
vsushko committed Dec 18, 2023
1 parent 879a057 commit 3e5137c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
18 changes: 13 additions & 5 deletions react-the-complete-guide/elegant-context-project/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { useState } from 'react';
import { useState } from "react";

import Header from './components/Header.jsx';
import Shop from './components/Shop.jsx';
import { DUMMY_PRODUCTS } from './dummy-products.js';
import Header from "./components/Header.jsx";
import Shop from "./components/Shop.jsx";
import Product from "./components/Product.jsx";

import { DUMMY_PRODUCTS } from "./dummy-products.js";

function App() {
const [shoppingCart, setShoppingCart] = useState({
Expand Down Expand Up @@ -71,7 +73,13 @@ function App() {
cart={shoppingCart}
onUpdateCartItemQuantity={handleUpdateCartItemQuantity}
/>
<Shop onAddItemToCart={handleAddItemToCart} />
<Shop>
{DUMMY_PRODUCTS.map((product) => (
<li key={product.id}>
<Product {...product} onAddToCart={handleAddItemToCart} />
</li>
))}
</Shop>
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import { DUMMY_PRODUCTS } from '../dummy-products.js';
import Product from './Product.jsx';

export default function Shop({ onAddItemToCart }) {
export default function Shop({ children }) {
return (
<section id="shop">
<h2>Elegant Clothing For Everyone</h2>

<ul id="products">
{DUMMY_PRODUCTS.map((product) => (
<li key={product.id}>
<Product {...product} onAddToCart={onAddItemToCart} />
</li>
))}
</ul>
<ul id="products">{children}</ul>
</section>
);
}

0 comments on commit 3e5137c

Please sign in to comment.