Use the Lifecycle Method componentWillMount - Helpp

Tell us what’s happening:

Your code so far


class MyComponent extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      activeUsers: null
    };
  }
  componentDidMount() {
    setTimeout( () => {
      this.setState({
        activeUsers: 5315
      });
    }, 2500);
  }
  render() {
    return (
      <div>
        <h1>Active Users: {this.state.activeUsers}</h1>
      </div>
    );
  }
};

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/react/use-the-lifecycle-method-componentwillmount

“Cannot read property ‘toString’ of undefined”

what you coded seems to work as intended but it has nothing to do with the challenge you are on. Maybe reset the challenge and start again

Not an expert of types within Javascript but it may not like you setting activeUsers to null. I would try giving it a default value of 1 or something of the sort and seeing if that changes anything.

Tell us what’s happening:

Your code so far


class MyComponent extends React.Component {
  constructor(props) {
    super(props);
  }
  componentWillMount() {
    // change code below this line

    // change code above this line
  }
  render() {
    return <div />
  }
};

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/react/use-the-lifecycle-method-componentwillmount/

Do you know how to log a message to the console with console.log()?

Yes, but I am in doubt on how to use this exercise!

Log something to the console within componentWillMount() - you may want to have your browser console open to see the output.

This is not even what the exercise is asking you to do. All you need to do is console.log() anything where you are asked to code.

``componentWillMount() {
// change code below this line

// change code above this line

}``