freeCodeCamp/guide/english/certifications/front-end-libraries/react/use-the-lifecycle-method-co.../index.md

833 B

title
Use the Lifecycle Method componentWillMount

Use the Lifecycle Method componentWillMount

The challenge is a basic introduction to React's LifeCycle components. These methods are also called Lifecycle Hooks.

Hint 1

Log something to the console in the react componentWillMount method.

Hint 2

The console.log(); statement is used to log to the browser console.

Solution

Since you can log anything, use the console.log(); and pass in a string. The componentWillMount method should look like:

componentWillMount() {
  console.log('Component being mounted');
}
Note: The componentWillMount Lifecycle method has been deprecated as of version 17, and does not work on later versions. (Source)