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);
|
this.handleClick = this.handleClick.bind(this);
|
||||||
}
|
}
|
||||||
handleClick() {
|
handleClick() {
|
||||||
this.setState({
|
this.setState(prevState => {
|
||||||
counter: 0 // Change this line
|
// Complete the return statement:
|
||||||
|
return {
|
||||||
|
counter: prevState
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
@ -280,8 +283,10 @@ class GameOfChance extends React.Component {
|
|||||||
this.handleClick = this.handleClick.bind(this);
|
this.handleClick = this.handleClick.bind(this);
|
||||||
}
|
}
|
||||||
handleClick() {
|
handleClick() {
|
||||||
this.setState({
|
this.setState(prevState => {
|
||||||
counter: this.state.counter + 1
|
return {
|
||||||
|
counter: prevState.counter + 1
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
|
Reference in New Issue
Block a user