From d70b17bca7a40f1869866fac4c31b083b1542523 Mon Sep 17 00:00:00 2001 From: suburban-daredevil <70901321+suburban-daredevil@users.noreply.github.com> Date: Thu, 27 May 2021 22:12:55 +0530 Subject: [PATCH] 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 Co-authored-by: Shaun Hamilton --- .../react/render-conditionally-from-props.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/curriculum/challenges/english/03-front-end-libraries/react/render-conditionally-from-props.md b/curriculum/challenges/english/03-front-end-libraries/react/render-conditionally-from-props.md index 6607403bb8..e69e98305a 100644 --- a/curriculum/challenges/english/03-front-end-libraries/react/render-conditionally-from-props.md +++ b/curriculum/challenges/english/03-front-end-libraries/react/render-conditionally-from-props.md @@ -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() {