Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何更改React中的输入字段值?_Reactjs - Fatal编程技术网

Reactjs 如何更改React中的输入字段值?

Reactjs 如何更改React中的输入字段值?,reactjs,Reactjs,我无法更改输入字段。有什么建议吗 constmiddlepanel=({user})=>{ const history=useHistory(); const[data,setData]=useState({ 名字:'', 姓氏:“”, 电子邮件:“”, 电话号码:'', }); const{firstname,lastname,email,phoneNo}=data; useffect(()=>{ const fetchUser=async()=>{ const res=等待axios.ge

我无法更改输入字段。有什么建议吗

constmiddlepanel=({user})=>{
const history=useHistory();
const[data,setData]=useState({
名字:'',
姓氏:“”,
电子邮件:“”,
电话号码:'',
});
const{firstname,lastname,email,phoneNo}=data;
useffect(()=>{
const fetchUser=async()=>{
const res=等待axios.get(`http://localhost:5000/users/${user.\u id}`);
设置数据({
firstname:res.data.firstname,
lastname:res.data.lastname,
电子邮件:res.data.email,
密码:res.data.password,
});
};
fetchUser();
},[user._id]);
常数handleChange=(e)=>{
setData({…data[e.target.name]:e.target.value});
};
const handleSubmit=async(e)=>{
e、 预防默认值();
const newUser={firstname,lastname,email,phoneNo};
试一试{
常量配置={
标题:{
“内容类型”:“应用程序/json”,
},
};
const body=JSON.stringify(newUser);
等待axios补丁(
`http://localhost:5000/users/${user.\u id}`,
身体,
配置
);
历史。推送(“/”);
}捕获(错误){}
};
返回(
更新
);

};
我认为应该使用
data.firstname
而不是
user
作为value属性


更新

哇,这段代码真的很难读懂,请您花点时间将代码正确格式化好吗?好的,很抱歉。