Anyone stuck on step 2 of Chapter 4 - componentWillUpdate?


#1


Lesson: Updating/Unmounting Lifecycle Methods
Chapter 4 - componentWillUpdate
Instruction 2 - adding if statement to componentWillUpdate

I cannot get my code to pass when I hit run. I get no error message. After hitting run a few times a popup appears that gives me the option to get the correct code. This popup does not work.

After trying to figure out where I went wrong with my code, I copied and pasted everything directly from the instructions. The problem remains. This is the code:


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 };
  },
  componentWillUpdate: function (nextProps, nextState) {
    if (document.body.style.background != yellow && this.state.highest >= 950*1000) {
      document.body.style.background = yellow;
    } else if (!this.props.game && nextProps.game) {
      document.body.style.background = 'white';
    }
  },
  render: function () {
    return (
      <h1>
        Top Number: {this.props.number}
      </h1>
    );
  }
});

module.exports = TopNumber;

I should add that I already submitted a bug report, but I wanted to make sure I hadn't missed something obvious.


#2

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