question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Challenge implies using anti-pattern which may have unexpected results in real situations

See original GitHub issue

Affected page https://www.freecodecamp.org/learn/front-end-libraries/react/render-conditionally-from-props

The lines 242-246 of the file read:

handleClick() {
  this.setState({
    counter: 0 // Change this line
  });
}

This implies that you can increment counter as follows: counter: this.state.counter + 1. As already taught at this point of the curriculum, this method can result in unexpected behavior, since React may batch state updates for performance reasons. AFAIK, the following is the correct way to handle this situation:

handleClick() {
  this.setState(prevState => ({counter: prevState.counter + 1}))
}

Expected behavior Right now, both methods of incrementing counter are accepted. I suggest we change the provided code and the tests so that only the second method is implied and accepted.

System:

  • Device: Laptop
  • OS: Ubuntu 20.4
  • Browser: Opera
  • Version: 76

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
lasjorgcommented, May 23, 2021

@suburban-daredevil There is already a PR for this which is awaiting requested changes. Let’s give them a chance to change what is needed first. If it does not happen within a reasonable timeframe we can use your PR instead.

1reaction
raisedadeadcommented, May 27, 2021

Hi @soham283 thanks for reaching out and we appreciate your help. We would like you to start here: https://contribute.freecodecamp.org/#/FAQ

Happy contribuitng.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is an Anti-Pattern? – BMC Software | Blogs
“An anti-pattern is a common response to a recurring problem that is usually ineffective and risks being highly counterproductive.” Note the ...
Read more >
Software Testing Anti-patterns - Codepipes Blog
Almost always the history behind this anti-pattern involves developers who believe that unit tests have no real value and only integration tests ...
Read more >
React course, incorrect usage of setState #39267 - GitHub
In the React lesson “Use State To Toggle An Element” ... using anti-pattern which may have unexpected results in real situations #42208.
Read more >
Anti-Pattern Detection: Methods, Challenges, and Open Issues
Anti-patterns are poor solutions to recurring design problems. They occur in object-oriented systems when developers unwillingly introduce them while designing ...
Read more >
4 DevOps anti-patterns that lead to disaster | TechBeacon
The problem arises when an anti-pattern becomes the new normal and the team stops there. The ability to recognize that you are using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found