Files

39 lines
944 B
Markdown
Raw Normal View History

---
title: Use the Lifecycle Method componentWillMount
---
# Use the Lifecycle Method componentWillMount
---
## 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.
---
## Hints
2018-10-16 14:14:34 +05:30
### Hint 1
2018-10-16 14:14:34 +05:30
Log something to the console in the ```react componentWillMount ``` method.
2018-10-16 14:14:34 +05:30
### Hint 2
The ``` console.log(); ``` statement is used to log to the browser console.
---
## Solutions
<details><summary>Solution 1 (Click to Show/Hide)</summary>
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:
```jsx
2018-10-16 14:14:34 +05:30
componentWillMount() {
console.log('Component being mounted');
}
```
2018-10-18 15:48:05 +05:30
**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>