回答編集履歴

2

こっちの方がいいかな

2021/06/04 02:54

投稿

FKM
FKM

スコア3647

test CHANGED
@@ -40,25 +40,21 @@
40
40
 
41
41
  const [val, setVal] = React.useState("");
42
42
 
43
- const [result, setResult] = React.useState(null);
43
+ const getVal = (e) => {
44
44
 
45
- const getVal = (val) => {
45
+ let val = ""
46
46
 
47
- let result = ""
47
+ if(e.indexOf('dog') !== -1){
48
48
 
49
- //ここでdogを含むかチェック
50
-
51
- if(val.indexOf('dog') !== -1){
52
-
53
- result = "犬派です"
49
+ val = "犬派です"
54
50
 
55
51
  }else if(e.indexOf('cat') !== -1){
56
52
 
57
- result = "猫派です"
53
+ val = "猫派です"
58
54
 
59
55
  }
60
56
 
61
- setResult(result)
57
+ setVal(val)
62
58
 
63
59
  };
64
60
 
@@ -112,7 +108,7 @@
112
108
 
113
109
  </label>
114
110
 
115
- <p>{result}</p>
111
+ <p>{val}</p>
116
112
 
117
113
  </>
118
114
 

1

consoleはいらない

2021/06/04 02:54

投稿

FKM
FKM

スコア3647

test CHANGED
@@ -57,8 +57,6 @@
57
57
  result = "猫派です"
58
58
 
59
59
  }
60
-
61
- console.log("R"+result)
62
60
 
63
61
  setResult(result)
64
62