-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProductsGrid.jsx
35 lines (33 loc) · 1.12 KB
/
ProductsGrid.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { Link, useLoaderData } from 'react-router-dom';
import { formatPrice } from '../utils';
const ProductsGrid = () => {
const { products } = useLoaderData();
return (
<div className='pt-12 grid gap-4 md:grid-cols-2 lg:grid-cols-3'>
{products.map((product) => {
const { title, price, image } = product.attributes;
const dollarsAmount = formatPrice(price);
return (
<Link
key={product.id}
to={`/products/${product.id}`}
className='card w-full shadow-xl hover:shadow-2xl transition duration-300'
>
<figure className='px-4 pt-4'>
<img
src={image}
alt={title}
className='rounded-xl h-64 md:h-48 w-full object-cover'
/>
</figure>
<div className='card-body items-center text-center'>
<h2 className='card-title capitalize tracking-wider'>{title}</h2>
<span className='text-secondary'>{dollarsAmount}</span>
</div>
</Link>
);
})}
</div>
);
};
export default ProductsGrid;