Skip to content

Commit 615b29a

Browse files
committed
improve the placeholders
1 parent 96f51ca commit 615b29a

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

src/components/List/ListComponent.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1-
import { ReactNode } from 'react'
1+
import React, { ReactNode } from 'react'
22
import { Placeholder } from 'src/components/placeholders'
33
import { MAX_ITEMS_PER_CARD } from 'src/config'
44
import { CarbonAd } from 'src/features/carbonAds'
55
import { BaseEntry } from 'src/types'
66

7+
type PlaceholdersProps = {
8+
placeholder: ReactNode
9+
}
10+
11+
const Placeholders = React.memo<PlaceholdersProps>(({ placeholder }) => {
12+
return (
13+
<>
14+
{[...Array(7)].map((x, i) => (
15+
<span key={i}>{placeholder}</span>
16+
))}
17+
</>
18+
)
19+
})
20+
721
export type ListComponentPropsType<T extends BaseEntry> = {
822
items: T[]
923
isLoading: boolean
@@ -44,15 +58,5 @@ export function ListComponent<T extends BaseEntry>(props: ListComponentPropsType
4458
})
4559
}
4660

47-
function Placeholders() {
48-
return (
49-
<>
50-
{[...Array(7)].map((x, i) => (
51-
<span key={i}>{placeholder}</span>
52-
))}
53-
</>
54-
)
55-
}
56-
57-
return <>{isLoading ? <Placeholders /> : renderItems()}</>
61+
return <>{isLoading ? <Placeholders placeholder={placeholder} /> : renderItems()}</>
5862
}

0 commit comments

Comments
 (0)