<input>标签上的prop`value`的值无效

Fle*_*ano 3 reactjs antd

我收到此警告,我无法解决:

value标签上prop的值无效。从元素中删除它,或者传递一个字符串或数字值以将其保留在DOM中。详情

以下是我正在使用的代码:

<FormItem validateStatus={NameError ? "error" : ""} help={NameError || ""}>
  {getFieldDecorator("Name", {
    initialValue: (()=>{this.state.Data.Name}),
    rules: [{ required: true, message: "Please input the component name!" }]
  })(
    <Input
      className="form-control"
      type="text"
      name="Name"
      defaultValue={this.state.Data.Name}
      onChange={this.onChange}
    />
  )}
</FormItem>
Run Code Online (Sandbox Code Playgroud)

我的打字稿界面看起来像这样:

export interface IFieldEdition{
    Data:IFieldData
}

export interface IFieldData{
    Id?:number,
    Name?:string,
    Value?:string,
    Description?:string,
    CreatedDate?:Date,
    CreatedBy?:string,
    StatusId?: number
}
Run Code Online (Sandbox Code Playgroud)

我该如何解决?有什么线索吗?

Har*_*vey 5

我看到您正在使用antd表单。从antd形式的正式文件

在由getFieldDecorator包装之后,值(或由valuePropName定义的其他属性)onChange(或由触发器定义的其他属性)道具将添加到表单控件中?表单数据流将由Form处理,这将导致:

您不应该手动调用setState,请使用this.props.form.setFieldsValue以编程方式更改值。

您使用initialValue: (()=>{this.state.Data.Name}调用setState可能是您收到此错误的原因。