这是我的父组件(网格),(这里我传递了更多 hoc 使用的道具,但我在这里省略了它们):
<QuickBooksTable itemList={quickBooksList} />
这是表格组件:
export const QuickBooksTable = withIntegrationTable(props: : WithIntegrationTableChildProps & WithIntegrationTableProps) => ...
这是临时的:
export function withIntegrationTable<T extends WithIntegrationTableProps>(Component: React.ComponentType<T>) {
return (
{
itemList,
...props
}: WithIntegrationTableProps & T
) => {
const [state, setState] = useState<WithIntegrationTableState>({
tableItems: new Array<any>(),
selectedItems: new Set<string>(),
isAllItemsSelected: false
});
useEffect(() => {
const tableItems = mapItemList(itemList, currentUser);
setState({
...state,
tableItems
});
}, [itemList]);
<Component {...props as T}
tableState={state}
/>
}
}
但是当它编译时它说:Element QuickBooksTable doesn't have required attribute (here is another props name)
. 我应该如何使用类型和泛型来消除这个错误?我试图阅读文档,但我不明白我做错了什么。