Skip to content

Commit

Permalink
type(List): fix type error.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Aug 25, 2022
1 parent 2f47047 commit ecd100e
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions packages/react-list/src/index.tsx
@@ -1,5 +1,5 @@
import React from 'react';
import { IProps, HTMLDivProps, noop } from '@uiw/utils';
import { IProps, HTMLDivProps } from '@uiw/utils';
import { ListItem } from './Item';
import './style/index.less';

Expand All @@ -25,7 +25,7 @@ function InternalList<T>(props: ListProps<T>, ref: React.ForwardedRef<HTMLDivEle
noHover = false,
active = false,
size = 'default',
renderItem = noop,
renderItem,
className,
children,
header,
Expand All @@ -35,7 +35,7 @@ function InternalList<T>(props: ListProps<T>, ref: React.ForwardedRef<HTMLDivEle
} = props;
let items: React.ReactNode;
if (dataSource && dataSource.length > 0) {
items = dataSource.map((item: any, index: number) => renderItem!(item, index));
items = dataSource.map((item: any, index: number) => renderItem && renderItem!(item, index));
} else {
items = children;
}
Expand Down Expand Up @@ -68,11 +68,8 @@ function InternalList<T>(props: ListProps<T>, ref: React.ForwardedRef<HTMLDivEle
);
}

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

(List as List).Item = ListItem;

export default List as List;
export default List;

0 comments on commit ecd100e

Please sign in to comment.