-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from 202306-NEA-DZ-FEW/11-feature-all_products…
…-page feat(allproducts page): create all products page to display all products
- Loading branch information
Showing
3 changed files
with
28 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<div> | ||
<h1 className="text-3xl text-center font-semibold py-2">All Products</h1> | ||
<div className="grid grid-cols-3 gap-6 mx-auto p-16 justify-center bg-slate-100"> | ||
{products.map((product) => { | ||
return <ShoppingCard key={product.id} {...product} /> | ||
})} | ||
</div> | ||
</div> | ||
) | ||
} | ||
export default AllProducts |