2018-10-04 14:47:55 +01:00
---
title: Use the Lifecycle Method componentWillMount
---
2019-07-24 00:59:27 -07:00
# Use the Lifecycle Method componentWillMount
2018-10-04 14:47:55 +01:00
2019-07-24 00:59:27 -07:00
---
## Problem Explanation
2018-10-16 14:14:34 +05:30
The challenge is a basic introduction to React's LifeCycle components.
These methods are also called Lifecycle Hooks.
2018-10-04 14:47:55 +01:00
2019-07-24 00:59:27 -07:00
---
## Hints
2018-10-16 14:14:34 +05:30
### Hint 1
2018-10-04 14:47:55 +01:00
2018-10-16 14:14:34 +05:30
Log something to the console in the ```react componentWillMount ` `` method.
2018-10-16 01:24:55 +05:30
2018-10-16 14:14:34 +05:30
### Hint 2
2018-10-16 01:24:55 +05:30
2019-07-24 00:59:27 -07:00
The ``` console.log(); ` `` statement is used to log to the browser console.
---
## Solutions
2018-10-16 01:24:55 +05:30
2019-07-24 00:59:27 -07:00
< details > < summary > Solution 1 (Click to Show/Hide)< / summary >
2018-10-16 01:24:55 +05:30
2018-10-16 14:14:34 +05:30
Since you can log anything, use the ``` console.log(); ` `` and pass in a string. The ` `` componentWillMount ` `` method should look like:
2018-10-16 01:24:55 +05:30
2019-07-24 00:59:27 -07:00
```jsx
2018-10-16 14:14:34 +05:30
componentWillMount() {
console.log('Component being mounted');
}
2018-10-16 01:24:55 +05:30
```
2018-10-18 15:48:05 +05:30
2019-07-24 00:59:27 -07:00
**Note:** The ``` componentWillMount ` `` Lifecycle method has been deprecated as of version 17, and does not work on later versions. [(Source) ](https://reactjs.org/docs/react-component.html )
< / details >