【发布时间】:2020-07-04 06:26:10
【问题描述】:
使用的原始代码-
import { Create } from '@material-ui/icons';
<DroppableFolder
count={draftsCount}
sidebarOpen={open}
folderId={FolderType.Drafts}
Icon={Create}
name="Drafts"
type="folder"
url={Communication.drafts}
/>
这是界面-
export default interface DroppableFolderProps {
count?: number;
folderId: string;
label?: Label;
Icon?: React.ComponentType;
name?: string;
type: LinkType;
url: string;
sidebarOpen?: boolean;
}
关于用这个 React 功能组件替换 Icon={Create},
const DraftIcon = <Icon icon="draft-icon" title="Draft Icon" size="medium" />;
<DroppableFolder
count={draftsCount}
sidebarOpen={open}
folderId={FolderType.Drafts}
Icon={DraftIcon}
name="Drafts"
type="folder"
url={Communication.drafts}
/>
我收到此错误 -
type 'Element' is not assignable to type 'ComponentClass<{}, any> | FunctionComponent<{}> | undefined'.
Type 'Element' is not assignable to type 'FunctionComponent<{}>'.
Type 'Element' provides no match for the signature '(props: { children?: ReactNode; }, context?: any): ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<...>)> | null'.
对于Icon={DraftIcon}这一行。
有什么建议吗?
【问题讨论】:
标签: reactjs typescript react-hooks