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

28 lines
833 B
Markdown
Raw Normal View History

---
title: Use the Lifecycle Method componentWillMount
---
## Use the Lifecycle Method componentWillMount
2018-10-16 08:44:34 +00:00
The challenge is a basic introduction to React's LifeCycle components.
These methods are also called Lifecycle Hooks.
2018-10-16 08:44:34 +00:00
### Hint 1
2018-10-16 08:44:34 +00:00
Log something to the console in the ```react componentWillMount ``` method.
2018-10-16 08:44:34 +00:00
### Hint 2
2018-10-16 08:44:34 +00:00
The `` console.log(); `` statement is used to log to the browser console.
2018-10-16 08:44:34 +00:00
### Solution
2018-10-16 08:44:34 +00:00
Since you can log anything, use the ``` console.log(); ``` and pass in a string. The ``` componentWillMount ``` method should look like:
```javascript
2018-10-16 08:44:34 +00:00
componentWillMount() {
console.log('Component being mounted');
}
```
2018-10-18 10:18:05 +00: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)