feat(curriculum): update handleclick method to use state function (#42225)
* Updated the handleClick method to use updater function in react tutorial english * Update comments in the seed code of curriculum/challenges/english/03-front-end-libraries/react/render-conditionally-from-props.md Changing comments in the seed code according to the list of [agreed-upon comments](https://github.com/freeCodeCamp/freeCodeCamp/blob/main/curriculum/dictionaries/english/comments.json) Co-authored-by: Shaun Hamilton <shauhami020@gmail.com> Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>
This commit is contained in:
committed by
GitHub
parent
3c36bda9ab
commit
d70b17bca7
@ -240,8 +240,11 @@ class GameOfChance extends React.Component {
|
||||
this.handleClick = this.handleClick.bind(this);
|
||||
}
|
||||
handleClick() {
|
||||
this.setState({
|
||||
counter: 0 // Change this line
|
||||
this.setState(prevState => {
|
||||
// Complete the return statement:
|
||||
return {
|
||||
counter: prevState
|
||||
}
|
||||
});
|
||||
}
|
||||
render() {
|
||||
@ -280,8 +283,10 @@ class GameOfChance extends React.Component {
|
||||
this.handleClick = this.handleClick.bind(this);
|
||||
}
|
||||
handleClick() {
|
||||
this.setState({
|
||||
counter: this.state.counter + 1
|
||||
this.setState(prevState => {
|
||||
return {
|
||||
counter: prevState.counter + 1
|
||||
}
|
||||
});
|
||||
}
|
||||
render() {
|
||||
|
Reference in New Issue
Block a user