Skip to content

Commit

Permalink
feat: add lazy loading to content-card image
Browse files Browse the repository at this point in the history
  • Loading branch information
olexh committed May 27, 2024
1 parent 215c6a7 commit 875df03
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 3 additions & 1 deletion components/content-card/content-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ const Content = memo(
posterClassName,
)}
alt="Poster"
{...posterProps}
{...(posterProps
? posterProps
: { loading: 'lazy' })}
/>
) : (
poster
Expand Down
9 changes: 5 additions & 4 deletions components/ui/image.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use client';

import clsx from 'clsx';
import NextImage, { ImageProps } from 'next/image';
import React, { Ref, forwardRef, useState } from 'react';
import { Ref, forwardRef, useState } from 'react';

import { cn } from '@/utils/utils';

interface Props extends ImageProps {
transitionDisabled?: boolean;
Expand All @@ -17,8 +18,8 @@ const Component = (
return (
<NextImage
ref={ref}
className={clsx(
loaded ? 'opacity-1' : 'opacity-0',
className={cn(
loaded ? 'opacity-100' : 'opacity-0',
!transitionDisabled && '!transition',
className,
)}
Expand Down
2 changes: 1 addition & 1 deletion components/user-cover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const UserCover: FC<Props> = ({ username }) => {
className="relative size-full object-cover"
alt="cover"
fill
priority
loading="lazy"
/>
</div>
);
Expand Down

0 comments on commit 875df03

Please sign in to comment.