componentWillUpdate, exercise 2


#1


https://www.codecademy.com/en/courses/react-102/lessons/updating-unmounting-lifecycle-methods/exercises/componentwillupdate


Hi, folks. I've seen this mentioned in some older posts, but I haven't seen a solution, or an indication that this has been solved, but the second exercise on componentWillUpdate, I added the code but got a syntax error. Couldn't find said syntax error, so I ended up copying and pasting the code in the exercise listing, and got the same syntax error.

It gets weirder. I got the "Having trouble" prompt, but it would not let me click the "Get Code", however the "No, thanks" worked just fine. Finally, after multiple tries, I attempted to reset the exercise, whereupon I was promptly disconnected from the server. Further tries have shaped up the same way.

So, does anybody know a workaround? Or is this one of the magic bugs that keep popping up?

Edit: attaching the code, since I finally got it to come up without freezing. I tried a couple of edits in an attempt to remove ambiguity, but they have accomplished nothing yet.

var React = require('react');
var ReactDOM = require('react-dom');
var yellow = 'rgb(255, 215, 18)';

var TopNumber = React.createClass({
propTypes: {
number: React.PropTypes.number,
game: React.PropTypes.bool
},

getInitialState: function () {
return { 'highest': 0 };
},

componentWillReceiveProps: function (nextProps) {
if (nextProps.number > this.state.highest) {
this.setState({
highest: nextProps.number
});
} else if (!this.props.game) {
this.setState({
highest: 0
});
}
},

componentWillUpdate: function(){
if ((document.body.style.background != yellow)
&& (this.state.highest >= 950000)) {
document.body.style.background = yellow;
} else if (!this.props.game
&& nextProps.game) {
document.body.style.background = 'white';
}
},

render: function () {
return (


Top Number: {this.state.highest}


);
}
});

module.exports = TopNumber;



#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.