質問編集履歴
2
App.js 全文の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -35,3 +35,37 @@
|
|
35
35
|
```
|
36
36
|
formには、react-hook-formをインポートしています。
|
37
37
|
|
38
|
+
以下が、App.js の全文です。
|
39
|
+
|
40
|
+
```react
|
41
|
+
/* App.js */
|
42
|
+
|
43
|
+
import { useState } from "react";
|
44
|
+
import { useForm } from "react-hook-form";
|
45
|
+
|
46
|
+
export function App() {
|
47
|
+
const { register, setValue, handleSubmit } = useForm();
|
48
|
+
const [formdata, setData] = useState("");
|
49
|
+
|
50
|
+
|
51
|
+
return (
|
52
|
+
<div style={{ 'padding': '20px' }}>
|
53
|
+
<form onSubmit={handleSubmit((formdata) => setData(JSON.stringify(formdata)))}>
|
54
|
+
<input {...register("aaa")} type="text" name="aaa" />
|
55
|
+
<input {...register("bbb")} type="text" name="bbb" />
|
56
|
+
<input type="submit" />
|
57
|
+
</form>
|
58
|
+
|
59
|
+
<div>formdata=「{formdata}」</div>
|
60
|
+
<div>formdata.aaa=「{formdata.aaa}」</div>
|
61
|
+
<div>formdata.bbb=「{formdata.bbb}」</div>
|
62
|
+
|
63
|
+
{console.log(formdata)}
|
64
|
+
|
65
|
+
</div >
|
66
|
+
|
67
|
+
);
|
68
|
+
}
|
69
|
+
|
70
|
+
export default App;
|
71
|
+
```
|
1
使用formの明記
test
CHANGED
File without changes
|
test
CHANGED
@@ -33,3 +33,5 @@
|
|
33
33
|
<input type="submit" />
|
34
34
|
</form>
|
35
35
|
```
|
36
|
+
formには、react-hook-formをインポートしています。
|
37
|
+
|