Skip to content

Commit 4b869ed

Browse files
committed
feat: add lazyload image
1 parent 0bc6307 commit 4b869ed

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/components/Item.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import getCookie from '../utils/cookie'
66
import { HeartIcon as HeartIconSolid } from '@heroicons/react/solid'
77
import { HeartIcon } from '@heroicons/react/outline'
88
import { classNames } from '../utils/styling'
9+
import { LazyLoadImage } from 'react-lazy-load-image-component';
10+
import 'react-lazy-load-image-component/src/effects/blur.css';
11+
import PlaceholderImage from '../assets/dummy_275x360_ffffff_cccccc.png';
912

1013
function handleClick() {
1114
sessionStorage.setItem('scrollPosition', window.pageYOffset)
@@ -65,11 +68,11 @@ const Item = (props) => {
6568
<div key={item.id} data-id={item.id} className="group relative">
6669
{item.image_url ? (<div className="w-full min-h-80 bg-gray-200 aspect-w-1 aspect-h-1 rounded-md overflow-hidden group-hover:opacity-75 lg:h-80 lg:aspect-none">
6770

68-
<img src={item.image_url} alt={item.name} className="w-full h-full object-center object-cover lg:w-full lg:h-full" />
71+
<LazyLoadImage src={item.image_url} alt={item.name} height={'100%'} width={'100%'} placeholdersrc={PlaceholderImage} className="w-full h-full object-center object-cover lg:w-full lg:h-full" effect="blur" />
6972

7073
</div>) : (
7174
<div className="w-full min-h-80 bg-gray-200 aspect-w-1 aspect-h-1 rounded-md overflow-hidden group-hover:opacity-75 lg:h-80 lg:aspect-none">
72-
<img src={item.image} alt={item.name} className="w-full h-full object-center object-cover lg:w-full lg:h-full" />
75+
<LazyLoadImage src={item.image} alt={item.name} placeholdersrc={PlaceholderImage} className="w-full h-full object-center object-cover lg:w-full lg:h-full" effect="blur" />
7376
</div>
7477
)}
7578
<div className="mt-4 flex justify-between">
5.67 KB
Loading

0 commit comments

Comments
 (0)