From 4425a5208ac19873403184c1db5e9fdc2e8e6851 Mon Sep 17 00:00:00 2001 From: hocine1212 Date: Thu, 28 Sep 2023 18:19:54 +0100 Subject: [PATCH] feat(allproducts page): create all products page to display all products fix #11 --- src/components/ShoppingCard/ShoppingCard.jsx | 3 --- src/pages/products/index.js | 5 ---- src/pages/products/index.jsx | 28 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) delete mode 100644 src/pages/products/index.js create mode 100644 src/pages/products/index.jsx diff --git a/src/components/ShoppingCard/ShoppingCard.jsx b/src/components/ShoppingCard/ShoppingCard.jsx index a423228..8d48d44 100644 --- a/src/components/ShoppingCard/ShoppingCard.jsx +++ b/src/components/ShoppingCard/ShoppingCard.jsx @@ -12,13 +12,11 @@ export default function ShoppingCard({ id, title, image, price, rating }) { {title}

- {title.length > 25 ? `${title.slice(0, 25)}...` : title}

@@ -28,7 +26,6 @@ export default function ShoppingCard({ id, title, image, price, rating }) {

{price}$

-
diff --git a/src/pages/products/index.js b/src/pages/products/index.js deleted file mode 100644 index 37abe94..0000000 --- a/src/pages/products/index.js +++ /dev/null @@ -1,5 +0,0 @@ -import React from "react" - -export default function Products() { - return
Products
-} diff --git a/src/pages/products/index.jsx b/src/pages/products/index.jsx new file mode 100644 index 0000000..eb1ad59 --- /dev/null +++ b/src/pages/products/index.jsx @@ -0,0 +1,28 @@ +import ShoppingCard from "@/components/ShoppingCard/ShoppingCard" + +import { useEffect, useState } from "react" + +const AllProducts = () => { + const [products, setProducts] = useState([]) + + function fetchProducts() { + fetch("https://fakestoreapi.com/products") + .then((res) => res.json()) + .then((products) => setProducts(products)) + } + useEffect(() => { + fetchProducts() + }, []) + + return ( +
+

All Products

+
+ {products.map((product) => { + return + })} +
+
+ ) +} +export default AllProducts