From 66d95eda48419c778904b0d95f28c80b623143f2 Mon Sep 17 00:00:00 2001 From: The Coding Aviator <34807532+thecodingaviator@users.noreply.github.com> Date: Tue, 16 Oct 2018 14:14:34 +0530 Subject: [PATCH] Update index.md (#19452) --- .../index.md | 50 ++++--------------- 1 file changed, 11 insertions(+), 39 deletions(-) diff --git a/client/src/pages/guide/english/certifications/front-end-libraries/react/use-the-lifecycle-method-componentwillmount/index.md b/client/src/pages/guide/english/certifications/front-end-libraries/react/use-the-lifecycle-method-componentwillmount/index.md index bd242ac698..b260882d1f 100644 --- a/client/src/pages/guide/english/certifications/front-end-libraries/react/use-the-lifecycle-method-componentwillmount/index.md +++ b/client/src/pages/guide/english/certifications/front-end-libraries/react/use-the-lifecycle-method-componentwillmount/index.md @@ -3,51 +3,23 @@ title: Use the Lifecycle Method componentWillMount --- ## Use the Lifecycle Method componentWillMount -This challenges introduces the ``` componentWillMount ``` Lifecycle method. This is used to set state after a giventime period. +The challenge is a basic introduction to React's LifeCycle components. +These methods are also called Lifecycle Hooks. -The syntax for the method is: -```javascript -componentDidMount() { - setTimeout( () => { - this.setState({ - one: 1, - two: false - }); - }, interval); - } -``` -where ``` one ``` and ``` two ``` are states you want to set after ``` interval ```ms. +### Hint 1 -### Hint +Log something to the console in the ```react componentWillMount ``` method. -Use -```javascript -this.state.stateName -``` -and change ``` stateName ``` as required. +### Hint 2 + +The `` console.log(); `` statement is used to log to the browser console. ### Solution -Change -```javascript -render() { - return ( -
-

Active Users: { /* change code here */ }

-
- ); - } -``` - -to +Since you can log anything, use the ``` console.log(); ``` and pass in a string. The ``` componentWillMount ``` method should look like: ```javascript -render() { - return ( -
-

Active Users: { this.state.activeUsers }

-
- ); - } +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)](https://reactjs.org/docs/react-component.html)