|
1 | | -import React, { ReactNode, useMemo } from 'react' |
| 1 | +import React, { memo, ReactNode, useMemo } from 'react' |
2 | 2 | import { Placeholder } from 'src/components/placeholders' |
3 | 3 | import { MAX_ITEMS_PER_CARD } from 'src/config' |
4 | 4 |
|
5 | 5 | type PlaceholdersProps = { |
6 | 6 | placeholder: ReactNode |
7 | 7 | } |
8 | 8 |
|
9 | | -const Placeholders = React.memo<PlaceholdersProps>(({ placeholder }) => { |
| 9 | +const Placeholders = memo<PlaceholdersProps>(({ placeholder }) => { |
10 | 10 | return ( |
11 | 11 | <> |
12 | 12 | {[...Array(7)].map((_, i) => ( |
@@ -42,18 +42,6 @@ export function ListComponent<T extends any>(props: ListComponentPropsType<T>) { |
42 | 42 | limit = MAX_ITEMS_PER_CARD, |
43 | 43 | } = props |
44 | 44 |
|
45 | | - if (error) { |
46 | | - return <p className="errorMsg">{error?.message || error}</p> |
47 | | - } |
48 | | - |
49 | | - if (items && items.length == 0) { |
50 | | - return ( |
51 | | - <p className="errorMsg"> |
52 | | - No items found, try adjusting your filter or choosing a different tag. |
53 | | - </p> |
54 | | - ) |
55 | | - } |
56 | | - |
57 | 45 | const sortedData = useMemo(() => { |
58 | 46 | if (!items || items.length == 0) return [] |
59 | 47 | if (!sortBy) return items |
@@ -88,7 +76,19 @@ export function ListComponent<T extends any>(props: ListComponentPropsType<T>) { |
88 | 76 | } catch (e) { |
89 | 77 | return [] |
90 | 78 | } |
91 | | - }, [sortedData]) |
| 79 | + }, [sortedData, header, renderItem, limit]) |
| 80 | + |
| 81 | + if (error) { |
| 82 | + return <p className="errorMsg">{error?.message || error}</p> |
| 83 | + } |
| 84 | + |
| 85 | + if (items && items.length == 0) { |
| 86 | + return ( |
| 87 | + <p className="errorMsg"> |
| 88 | + No items found, try adjusting your filter or choosing a different tag. |
| 89 | + </p> |
| 90 | + ) |
| 91 | + } |
92 | 92 |
|
93 | 93 | return <>{isLoading ? <Placeholders placeholder={placeholder} /> : enrichedItems}</> |
94 | 94 | } |
0 commit comments