I am learning ReactJS and I wanted to know the difference in using curly braces and parenthesis for return statements.
Here is a block of code
class App extends React.Component {
constructor() {
super();
this.state = {
count: 0
};
this.handleClick = this.handleClick.bind(this)
}
handleClick() {
this.setState(prevState => {
return {
count: prevState.count + 1
}
})
}
render() {
return (
<div>
<h1>{this.state.count}</h1>
<br />
<button onClick={this.handleClick}>Change!</button>
</div>
);
}
}
export default App
In the handleClick
function, return
has curly braces and in the render
function, it has parenthesis.
Interchanging them in either case gives me an Error.
So...I just wanted to know if there is any difference and which one is to be used when