質問編集履歴
1
具体例を書きました
test
CHANGED
File without changes
|
test
CHANGED
@@ -1 +1,71 @@
|
|
1
1
|
Reactで`()`と`{}`の違いがわからないのですが、どういった違いがあるのですか?
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
例えばですけど下記のコードで`return`に`()`を使っているところもあれば`{}`を使っているところもあります。
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
```
|
10
|
+
|
11
|
+
import React from 'react';
|
12
|
+
|
13
|
+
import './Color.css';
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
class Color extends React.Component {
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
constructor(props) {
|
22
|
+
|
23
|
+
super(props);
|
24
|
+
|
25
|
+
this.state = {
|
26
|
+
|
27
|
+
count: 0
|
28
|
+
|
29
|
+
};
|
30
|
+
|
31
|
+
this.countUp = this.countUp.bind(this);
|
32
|
+
|
33
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
countUp() {
|
38
|
+
|
39
|
+
this.setState(prevState => {
|
40
|
+
|
41
|
+
return {
|
42
|
+
|
43
|
+
count: prevState.count + 1
|
44
|
+
|
45
|
+
};
|
46
|
+
|
47
|
+
});
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
render() {
|
52
|
+
|
53
|
+
return (
|
54
|
+
|
55
|
+
<li style={{backgroundColor:this.props.color}} onClick={this.countUp}>
|
56
|
+
|
57
|
+
{this.state.count}
|
58
|
+
|
59
|
+
</li>
|
60
|
+
|
61
|
+
);
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
export default Color
|
70
|
+
|
71
|
+
```
|