【发布时间】:2021-03-20 12:15:02
【问题描述】:
import React, { useState } from 'react';
const Contact = () => {
const [data] = useState({
fullname: '',
//More data here
});
const formSubmit = () => {
// Some more Code
};
return (
<>
<form onSubmit={formSubmit}>
<div class="mb-3">
<label for="exampleFormControlInput1" class="form-label">
Full Name
</label>
<input
type="text"
class="form-control"
id="exampleFormControlInput1"
name="fullname"
value={data.fullname}
//onChange={InputEvent}
placeholder=" Your name"
required
/>
</div>
</form>
</>
);
}
我想在值中使用全名,我做了data.fullname 这有什么问题,为什么会出现 Invalid Hook call 错误。
注意:- 我已经评论过 Onchange 这件事与钩子无关,而且 OnSubmit 有更多代码。
【问题讨论】:
-
它运作良好。 codesandbox.io/s/eager-lewin-u216i ..
-
@prasanth 在 VScode 中不起作用,你知道我的 VS 代码编辑器或其他什么问题吗
-
您的退货声明已开始
(但没有结束) -
@theTradeCoder 更新:- 返回结束标签添加它在代码中,但我忘了在这里添加。
-
您的代码运行良好 - 问题来自其他地方...
标签: reactjs react-hooks react-hook-form