I wrote some react JS code here:
import React from "react"
class App extends React.Component {
constructor() {
super();
this.state = {
count: 0
};
this.handleClick = this.handleClick.bind(this);
}
handleClick(prevState){
this.setState(prevState => {count: prevState.count +1});
}
render() {
return (
<div>
<h1>{this.state.count}</h1>
<button onClick={this.handleClick}>Increment</button>
</div>
);
}
}
This crushed the entire program. Here, arrow function has only one statement, So I removed the brackets and the return keyword, even if I add return
keyword, it won't work either.
handleClick(prevState){
this.setState(prevState => return {count: prevState.count +1});
}
what is happening? What am I missing, thank you