Seb*_*ien 6 typescript reactjs
我有一个包装蚂蚁设计形式的组件,如下所示:
export interface IMyProps {
onSubmit: () => void,
anInput: React.ReactNode
}
export class MyForm extends React.Component<IMyProps> {
constructor(props: any) {
super(props)
}
render() {
return (
<Form onSubmit={this.props.onSubmit}>
{this.props.anInput}
</Form>
)
}
}
Run Code Online (Sandbox Code Playgroud)
我希望能够将任何ReactNode传递给我的表单结构和一个处理表单提交的函数。
因此,我还有一个用于定义传递给MyForm的组件的组件:
export interface IDecoratorProps extends FormComponentProps {
onSubmit: () => void,
value: string
}
class MyDecoratedForm extends React.Component<IDecoratorProps> {
constructor(props: any) {
super(props)
}
render() {
return (
<div>
<MyForm
onSubmit={this.props.onSubmit}
anInput={
<Form.Item
label={"label"}
hasFeedback>
{
this.props.form.getFieldDecorator(
"label",
{
rules: [{required: true, message: 'This is required'}]
}
)
(
< Input size="large" type="text" value={this.props.value}/>
)
}
</Form.Item>
}/>
</div>
)
}
}
export const MyFormDecorator = Form.create<IDecoratorProps>()(MyDecoratedForm);
Run Code Online (Sandbox Code Playgroud)
最后,我有应该传递值属性和onSubmit属性的Page组件。
像这样:
...
render() {
<MyFormDecorator value={this.state.value} onSubmit={() => {}}/>
}
Run Code Online (Sandbox Code Playgroud)
我的问题是我有一个
TS2339:类型“ IntrinsicAttributes和IntrinsicClassAttributes,ComponentState >>和...上不存在属性'value'
| 归档时间: |
|
| 查看次数: |
376 次 |
| 最近记录: |