diff --git a/dummy_products/src/App.jsx b/dummy_products/src/App.jsx index c75b94f..d08043c 100644 --- a/dummy_products/src/App.jsx +++ b/dummy_products/src/App.jsx @@ -1,10 +1,12 @@ import Header from "./components/Header" +import Products from "./components/Products" function App() { return (
+
) } diff --git a/dummy_products/src/components/Product.jsx b/dummy_products/src/components/Product.jsx index 9900aed..e378bb1 100644 --- a/dummy_products/src/components/Product.jsx +++ b/dummy_products/src/components/Product.jsx @@ -1,6 +1,6 @@ -function Product({ product }) { +function Product({ product,kapcsol }) { return (
@@ -14,7 +14,7 @@ function Product({ product }) {

{product.description}

- +
diff --git a/dummy_products/src/components/ProductDetails.jsx b/dummy_products/src/components/ProductDetails.jsx new file mode 100644 index 0000000..2b35ede --- /dev/null +++ b/dummy_products/src/components/ProductDetails.jsx @@ -0,0 +1,41 @@ + + +function ProductDetails({ product,kapcsol }) { + return ( +
+
+ {product.title} +
+
+

+ {product.title} + + +

+
+ Ratings: + { + product.reviews.map((review) => + (
{review.rating}
)) + } + +
+

{product.description}

+
+ + { + product.reviews.map((review) => + (
{review.comment}
)) + } +
+
+ +
+
+
+ ) +} + +export default ProductDetails \ No newline at end of file diff --git a/dummy_products/src/components/ProductRender.jsx b/dummy_products/src/components/ProductRender.jsx new file mode 100644 index 0000000..3527c68 --- /dev/null +++ b/dummy_products/src/components/ProductRender.jsx @@ -0,0 +1,25 @@ +import { useState } from "react" +import ProductDetails from "./ProductDetails"; +import Product from "./Product"; + +function ProductRender({product}) { + const[isOpen,setIsOpen]=useState(false); + + const kapcsol=()=>{ + //A state előző állapotát felhasználva állítom be az új állapotot + setIsOpen(prev=>!prev); + } + + return ( +
+ { + isOpen ? + + : + + } +
+ ) +} + +export default ProductRender \ No newline at end of file diff --git a/dummy_products/src/components/Products.jsx b/dummy_products/src/components/Products.jsx index 62a034b..fb9d234 100644 --- a/dummy_products/src/components/Products.jsx +++ b/dummy_products/src/components/Products.jsx @@ -1,18 +1,40 @@ import Product from "./Product"; +import ProductRender from "./ProductRender"; import { useState,useEffect } from "react"; function Products() { const[products,setProducts]=useState([]); const getProducts=()=>{ - + fetch('https://dummyjson.com/products') + .then(res=>res.json()) + .then(adatok=>setProducts(adatok.products)) + .catch(err=>alert(err)); } + + const asyncGetProducts=async ()=>{ + try { + const keres=await fetch('https://dummyjson.com/products'); + const valasz=await keres.json(); + setProducts(valasz.products); + + } catch (error) { + alert(error); + } + } + useEffect(()=>{ - getProducts(); + //getProducts(); + asyncGetProducts(); },[]); return (

Termékek:

+
+ { + products.map((product)=>()) + } +
) }