Use the Lifecycle Method componentWillMount-not passing in codepen

<%= @topic_view.topic.title %>
<%= @topic_view.topic.average_rating %> <%= @topic_view.topic.posts.count { |p| !!p.custom_fields['rating'] } %>

Tell us what’s happening:

I passed in fcc but not getting the output in codepen despite inserting everything behind the hood in codepen. wonder why?my codepen link is : [ https://codepen.io/meeramenon07/pen/WNeyepP]

Your code so far


class MyComponent extends React.Component {
  constructor(props) {
    super(props);
  }
  componentWillMount() {
    // change code below this line
      console.log(MyComponent);
    // change code above this line
  }
  render() {
    return <div />
  }
};

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36.

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

The console.log actually runs. It’s printing the component definition itself in the console.

1 Like

Hi, on a note not related to the challenge, but rather for future reference, I advise you to not use componentWillMount because it has been deprecated and it will be removed from the future versions of React (if it hasn’t been removed already).
Whatever you used to put before in the componentWillMount, now you should put them either in the constructor or in the definition of the componentDidMount method.
Take a look at Vladimir K.'s answer here on Stack Overflow.
The question is about React Native, but it applies to React as well.

1 Like