Skip to content

Commit

Permalink
refactor: Use useId instead of manually generating keys for loading s…
Browse files Browse the repository at this point in the history
…keletons
  • Loading branch information
ZeroWave022 committed Sep 22, 2024
1 parent 4b84038 commit f1a904e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/components/layout/PaginationCarouselSkeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
PaginationPrevious,
} from '@/components/ui/Pagination';
import { useTranslations } from 'next-intl';
import { useId } from 'react';

type PaginationCarouselSkeletonProps = {
className?: string;
};
Expand All @@ -28,10 +30,10 @@ function PaginationCarouselSkeleton({
tabIndex={-1}
/>
</PaginationItem>
{Array.from({ length: 4 }).map((_, index) => (
{Array.from({ length: 4 }).map(() => (
<PaginationItem
className='cursor-not-allowed opacity-50'
key={`Item ${index + 1}`}
key={useId()}
>
<PaginationEllipsis morePages='' />
</PaginationItem>
Expand Down
2 changes: 1 addition & 1 deletion src/components/news/CardGridSkeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function CardGridSkeleton() {
index === 1 && 'col-span-1 row-span-1 md:col-span-2',
index === 3 && 'xs:col-span-2 row-span-1 md:col-span-1',
)}
key={`Grid ${index + 1}`}
key={React.useId()}
/>
))}
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/news/ItemGridSkeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as React from 'react';
function ItemGridSkeleton() {
return (
<div className='grid min-h-[752px] grid-cols-1 gap-4 sm:min-h-[368px] sm:grid-cols-2 lg:min-h-[240px] lg:grid-cols-3'>
{Array.from({ length: 6 }).map((_, index) => (
<ArticleItemSkeleton key={`Item ${index + 1}`} />
{Array.from({ length: 6 }).map(() => (
<ArticleItemSkeleton key={React.useId()} />
))}
</div>
);
Expand Down
12 changes: 5 additions & 7 deletions src/components/storage/ShoppingCartTableSkeleton.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { Skeleton } from '@/components/ui/Skeleton';
import { useId } from 'react';

export default function ShoppingCartTableSkeleton() {
return (
<>
<div className='mt-4 grid grid-cols-10 gap-2'>
{Array.from({ length: 4 }).map((_, index) => (
<Skeleton className='col-span-1 h-5' key={`s_1_${index + 1}`} />
{Array.from({ length: 4 }).map(() => (
<Skeleton className='col-span-1 h-5' key={useId()} />
))}
</div>
{Array.from({ length: 4 }).map((_, index) => {
{Array.from({ length: 4 }).map(() => {
return (
<div
key={`s_2_${index + 1}`}
className='my-4 grid grid-cols-10 gap-2'
>
<div key={useId()} className='my-4 grid grid-cols-10 gap-2'>
<Skeleton className='col-span-1 h-10' />
<Skeleton className='col-span-3 h-10' />
<Skeleton className='col-span-5 h-10' />
Expand Down

0 comments on commit f1a904e

Please sign in to comment.