React Challenge shouldComponentUpdate
See original GitHub issueChallenge 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
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:25 (14 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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!
@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.