reactjs - 道具“价值”的值无效标签
问题描述
我收到了无法解决的警告:
value
标签上的道具值无效。要么将其从元素中移除,要么传递一个字符串或数值以将其保留在 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>
我的打字稿界面如下所示:
export interface IFieldEdition{
Data:IFieldData
}
export interface IFieldData{
Id?:number,
Name?:string,
Value?:string,
Description?:string,
CreatedDate?:Date,
CreatedBy?:string,
StatusId?: number
}
我该如何解决这个问题?有什么线索吗?
解决方案
我看到你正在使用 antd 表单。来自antd form官方文档:
被getFieldDecorator包裹后,表单控件中会添加value(或valuePropName定义的其他属性)onChange(或trigger定义的其他属性)props,表单数据的流动将由Form处理,这将导致:
您不应该手动调用 setState,请使用 this.props.form.setFieldsValue 以编程方式更改值。
您使用initialValue: (()=>{this.state.Data.Name}
, 调用 setState 可能是您收到此错误的原因。
推荐阅读
- php - 如何从我的 HTML 表单和 PHP 脚本创建单个文件,以便从弹出模式访问它?
- python - 将 cumxxx (sum, min...) 应用于 DataFrame 中不同大小的窗口
- mysql - mysql 服务器中的 xampp 3.2.4 出错。它显示“错误:MySQL 意外关闭”
- java - 如何对列表中两个不同类的字段进行排序?
- java - 如何在 java 命名查询中编写区分大小写的查询
- sql - 当我在 sqlite3 中使用 SUM(CASE WHEN .... THEN "column_name") 时,我得到了意想不到的结果
- ios - 如何更改 iPhone 部署目标
- reactjs - 基于角色的授权的正确位置
- azure-devops - Jira 与 AzureDevOps 板
- php - Laravel 6 用户登录时记住我的令牌错误