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.

React Challenge shouldComponentUpdate

See original GitHub issue

Challenge Name

React Optimize Re-Renders with shouldComponentUpdate

Issue Description

It seems submitted code true but there is a problem in last two tests resulting regular expression errors. Problem 1 async last part, assert Problem 2 async last part, assert

Browser Information

  • Browser Name, Version: Opera 49.0.2725.64
  • Operating System: Ubuntu 16.04
  • Mobile, Desktop, or Tablet: Desktop

Your Code

class OnlyEvens extends React.Component {
  constructor(props) {
    super(props);
  }
  shouldComponentUpdate(nextProps, nextState) {
    console.log('Should I update?');
     // change code below this line
    return !(nextProps['value'] % 2);
     // change code above this line
  }
  componentWillReceiveProps(nextProps) {
    console.log('Receiving new props...');
  }
  componentDidUpdate() {
    console.log('Component re-rendered.');
  }
  render() {
    return <h1>{this.props.value}</h1>
  }
};

class Controller extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      value: 0
    };
    this.addValue = this.addValue.bind(this);
  }
  addValue() {
    this.setState({
      value: this.state.value + 1
    });
  }
  render() {
    return (
      <div>
        <button onClick={this.addValue}>Add</button>
        <OnlyEvens value={this.state.value}/>
      </div>
    );
  }
};

Screenshot

image

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:25 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
raisedadeadcommented, Jan 16, 2018

Hi, @StephenMayeux its okay, now.

I have gone ahead and retrieved the changes from my local copy.

I personally did not want @r1chard5mith 's efforts go waste, and they should get their well deserved credits for working on it, in the first place. We are super excited to welcome everyone, especially when when they are contributing to this code-base for first time.

The commit reflects them as an author.

@r1chard5mith @StephenMayeux Please feel free to take a look at the PR https://github.com/freeCodeCamp/freeCodeCamp/pull/16515 and suggest changes, I’ll be sure to make them.

Happy contributing!

0reactions
no-stack-dub-sackcommented, Jan 19, 2018

@r1chard5mith to answer one of your questions above: no, unfortunately there is no better way to test your changes to seed files than to edit the seed, reseed the database, and restart the server. Yes, the feedback loop is pretty slow, and if you’re just experimenting with stuff to see what works, it can get pretty frustrating. That said, it really does encourage you to think carefully about your changes because the desire becomes so strong to minimize the number of times you have to do this!

Also, I want to make sure we don’t lose track of the other issue you raised on this thread (about the weird rendering of async challenges, which I’ve noticed before when we first implemented them - but at that point, getting them working and in the codebase was enough). That said, I’m going to open this issue, but I will be sure to tag you in it, so you can follow what’s going on and suggest any solutions you might have.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReactJS shouldComponentUpdate() Method - GeeksforGeeks
It only updates the component if the props passed to it changes. The shouldComponentUpdate method is majorly used for optimizing the performance ...
Read more >
React shouldComponentUpdate demystified - Medium
This is where shouldComponentUpdate() comes into play. You can tell React not to render rows that do not need to be using this...
Read more >
React shouldComponentUpdate example with functional ...
Hi,. If we would like to use functional components instead of classes in this example, then how we should replace the ...
Read more >
Optimizing React.js Performance with PureComponents and ...
Today, we will be going over how to use React. ... PureComponents implicitly introduce a shouldComponentUpdate() lifecycle method to boost ...
Read more >
Memoization in React js - Topcoder
It depends on the shouldComponentUpdate() lifecycle method but it can only be used with the class component. React also gives us a memo()...
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