使用包含一些材料UI按钮的Material-UI Portal渲染组件。
<Portal container={this.myContainer}>
<Button onClick={this.handleClick}>Do something</Button>
//some other buttons
</Portal>
这会导致打字错误
TypeScript error: Type '{ children: Element[]; container: any; }' is not assignable to type 'Readonly<PortalProps>'.
Types of property 'children' are incompatible.
Type 'Element[]' is not assignable to type 'ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)>'.
材料ui核心v.3.9.0。找不到解决此特定问题的任何类型库
答案 0 :(得分:0)
可以通过使用单个div包裹门户内容来解决此错误:
<Portal container={this.myContainer}>
<div>
<Button onClick={this.handleClick}>
Do something
</Button>
//some other buttons
</div>
</Portal>