Skip to content

Commit ecd100e

Browse files
committedAug 25, 2022
type(List): fix type error.
1 parent 2f47047 commit ecd100e

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed
 

‎packages/react-list/src/index.tsx

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { IProps, HTMLDivProps, noop } from '@uiw/utils';
2+
import { IProps, HTMLDivProps } from '@uiw/utils';
33
import { ListItem } from './Item';
44
import './style/index.less';
55

@@ -25,7 +25,7 @@ function InternalList<T>(props: ListProps<T>, ref: React.ForwardedRef<HTMLDivEle
2525
noHover = false,
2626
active = false,
2727
size = 'default',
28-
renderItem = noop,
28+
renderItem,
2929
className,
3030
children,
3131
header,
@@ -35,7 +35,7 @@ function InternalList<T>(props: ListProps<T>, ref: React.ForwardedRef<HTMLDivEle
3535
} = props;
3636
let items: React.ReactNode;
3737
if (dataSource && dataSource.length > 0) {
38-
items = dataSource.map((item: any, index: number) => renderItem!(item, index));
38+
items = dataSource.map((item: any, index: number) => renderItem && renderItem!(item, index));
3939
} else {
4040
items = children;
4141
}
@@ -68,11 +68,8 @@ function InternalList<T>(props: ListProps<T>, ref: React.ForwardedRef<HTMLDivEle
6868
);
6969
}
7070

71-
const List = React.forwardRef<HTMLDivElement, ListProps<any>>(InternalList);
72-
type List = typeof List & {
73-
Item: typeof ListItem;
74-
};
71+
type ListComponent = React.FC<React.PropsWithRef<ListProps<any>>> & { Item: typeof ListItem };
72+
const List: ListComponent = React.forwardRef<HTMLDivElement>(InternalList) as unknown as ListComponent;
73+
List.Item = ListItem;
7574

76-
(List as List).Item = ListItem;
77-
78-
export default List as List;
75+
export default List;

0 commit comments

Comments
 (0)
Please sign in to comment.