From d25a4fcc4bad2f2227a1e43ad2ac18da653cbcf0 Mon Sep 17 00:00:00 2001 From: The Coding Aviator <34807532+thecodingaviator@users.noreply.github.com> Date: Tue, 16 Oct 2018 01:24:55 +0530 Subject: [PATCH] Added solution to Use the Lifecycle Method componentWillMount (#18760) --- .../index.md | 49 +++++++++++++++++-- 1 file changed, 46 insertions(+), 3 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 45bf7a31f0..bd242ac698 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,8 +3,51 @@ title: Use the Lifecycle Method componentWillMount --- ## Use the Lifecycle Method componentWillMount -This is a stub. Help our community expand it. +This challenges introduces the ``` componentWillMount ``` Lifecycle method. This is used to set state after a giventime period. -This quick style guide will help ensure your pull request gets accepted. +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 + +Use +```javascript +this.state.stateName +``` +and change ``` stateName ``` as required. + +### Solution + +Change +```javascript +render() { + return ( +
+

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

+
+ ); + } +``` + +to + +```javascript +render() { + return ( +
+

Active Users: { this.state.activeUsers }

+
+ ); + } +``` +##### 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)