質問編集履歴
1
具体例を書きました
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,1 +1,36 @@
|
|
1
|
-
Reactで`()`と`{}`の違いがわからないのですが、どういった違いがあるのですか?
|
1
|
+
Reactで`()`と`{}`の違いがわからないのですが、どういった違いがあるのですか?
|
2
|
+
|
3
|
+
例えばですけど下記のコードで`return`に`()`を使っているところもあれば`{}`を使っているところもあります。
|
4
|
+
|
5
|
+
```
|
6
|
+
import React from 'react';
|
7
|
+
import './Color.css';
|
8
|
+
|
9
|
+
class Color extends React.Component {
|
10
|
+
|
11
|
+
constructor(props) {
|
12
|
+
super(props);
|
13
|
+
this.state = {
|
14
|
+
count: 0
|
15
|
+
};
|
16
|
+
this.countUp = this.countUp.bind(this);
|
17
|
+
}
|
18
|
+
|
19
|
+
countUp() {
|
20
|
+
this.setState(prevState => {
|
21
|
+
return {
|
22
|
+
count: prevState.count + 1
|
23
|
+
};
|
24
|
+
});
|
25
|
+
}
|
26
|
+
render() {
|
27
|
+
return (
|
28
|
+
<li style={{backgroundColor:this.props.color}} onClick={this.countUp}>
|
29
|
+
{this.state.count}
|
30
|
+
</li>
|
31
|
+
);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
export default Color
|
36
|
+
```
|