Use the Lifecycle Method componentWillMount - Helpp

Use the Lifecycle Method componentWillMount - Helpp
0

#1

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


#2

What do you need help with?


#3

“Cannot read property ‘toString’ of undefined”


#4

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


#5

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.


#6

As @camelcamper points out, your code above has nothing to do with what is being asked of you for this particular challenge.


#7

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/


#8

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


#9

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


#10

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