您的位置:首页 > Web前端 > React

changing an uncontrolled input of type text to be controlled

2016-10-20 20:29 537 查看
menuAuth.js:1334 Warning: Form is changing an uncontrolled input of type text to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime
of the component.

重点在这里:uncontrolled input of type text to be controlled

从没有被react控制到现在要控制,提示这个报错,

我们知道react是     数据---》视图    

根据数据变化,使用虚拟dom找出变化的dom节点。然后最终更新。

那么这里为uncontrolled,即认为没有在可控数据范围类。。

<pre name="code" class="javascript"><input type="text" className="form-control" value={formData.name} placeholder="请输入名称"/>



原来我初始化的时候,未设置name值,

解决办法

1、formData  的值  formData.name="";

2、

<input type="text" className="form-control" value={formData.name||""} placeholder="请输入名称"/>


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐