• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
seegatesite header

Seegatesite.com

Seegatesite.com - Programming Tutorial , Sharing , How and Learn Together

  • TOOLS
    • Bootstrap Navbar Online Generator
    • Customize Sidebar Menu Bootstrap 3
    • Bootstrap Demo
  • ADVERTISE
  • CATEGORIES
    • Android
    • Blogging Tips
    • Database
    • CSS
    • Info Gadget
    • Javascript
    • Linux
    • PHP
    • Various
    • WordPress
  • Q&A
  • PHP
  • JAVASCRIPT
  • JQUERY
  • ANGULAR
  • WORDPRESS
  • SEO
  • REACT
🏠 » Javascript » The Right Way Understanding React Lifecycle For Beginners

The Right Way Understanding React Lifecycle For Beginners

By Sigit Prasetya Nugroho ∙ May 23, 2020 ∙ Javascript ∙ Leave a Comment

Share : TwitterFacebookTelegramWhatsapp

Each component in React has a life cycle that can be optimized to increase the effectiveness and performance of an application. As a beginner, you must understand every method in the lifecycle phase.

Like humans, react components have a lifecycle that can utilize to the maximum extent possible in making applications. When executed, the React component has a series of phases, and each phase provides methods that can be called when the component is in each phase. These functions are called reacts lifecycle methods.

Table of Contents

  • 1 React Components Lifecycle For Dummy
    • 1.1 1. Mounting Phase
    • 1.2 2. Updating phases
    • 1.3 3. Unmounting
  • 2 Conclusion

React Components Lifecycle For Dummy

By understanding the React component lifecycle, we can take certain actions, for example, when a component has created or when a component is about to be removed. In fact, with lifecycle methods, we can determine whether the component should be updated or not.

Look at the following diagram which to make it easier to understand the React Components Lifecycle.

React Components Lifecyle Diagrams
source : https://projects.wojtekmaj.pl/react-lifecycle-methods-diagram/

The Reacts Lifecycle component has 3 main phases:

  • Mounting phase
  • Updating phases
  • Unmounting phase

In each phase, The components execute the different methods known as reacts lifecycle methods.

1. Mounting Phase

This phase ran when the component rendered first to the DOM ie. Three main methods run in this phase, namely constructor, render, and componentDidMount.

constructor

Constructor Method Called React Components Lifecycle

When a component formed, the first method called is the constructor.

In addition to initializing the state values, a constructor method used to pass props to the extends reactcomponent.

The component class must always call the primary constructor with props.

render

Render Call

The render method uses to execute the JSX scripts to the DOM. In this rendering method, we wrote HTML code in a JSX and executed it to the DOM.

componentDidMount

Componentdidmount Parent Component

After the rendering method executed, the componentDidMount method is called. This method used to manipulate the DOM usually used to request data from the API.

2. Updating phases

This updating phases is the phase when a component re-rendered. This phase occurs when a change in the state or props results in changes to the DOM.

In this phase, there are several methods to be executed.

shouldComponentUpdate

Shouldcomponentupdate Method Returns

Method is call determine whether a component to be rendered again or not. This method returns  true or false values. If true, then the component re-rendered again or vice versa.

After the shouldComponentUpdate method returns true, then the render method is called again.

componentDidUpdate

Componentdidupdate In Updating Phase

Same as componentDidMount, which is for manipulation of DOM and request data after the component is re-rendered.

3. Unmounting

Unmounting is the phase when a component removed from the DOM.

Componentwillunmount Unmounting Phase

In this phase, only one method executed; namely, componentWillUnmount, which ran before a component removed from the DOM

There are several methods that I didn’t write down, and I explain in this article like getsnapshotbeforeupdate and getDerivedStateFromProps. Because basically, this method is very rare to use in several applications. But only for special cases

To better understand the components Lifecycle in ReactJS, Trying the following playground, see the console section.

Conclusion

  • Components Lifecycle is easy for us to add the business rules before components rendered to the DOM.
  • Lifecycle works every time there are changes to the state/props that result in changes to the DOM.
  • Lifecycle make performance optimizations increases in React App.
  • Props to stateful components declared in the constructor method

Thus the tutorial about the Lifecycle in ReactJS gets another react tutorial series on the React Tutorial For Beginners Series.

Another Javascript Related Post :

  • Adept Using Datatables Plugin In 10 Minutes For Beginners (Tutorial)
  • The Using Of Reactstrap And React-Table, Suitable For Beginners
  • Tutorial Create Simple Block UI Using React JS
  • How To Implement Login Page And Protected Route ReactJS
  • Complete Tutorial React Router Dom For Beginners (Easy-To-Understand)
  • [Problem Solved] React Error: ENOSPC: System limit for number of file watchers reached

Avatar for Sigit Prasetya Nugroho

About Sigit Prasetya Nugroho

This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Welcome to my Home,

Avatar for Sigit Prasetya NugrohoThis site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.



Popular Articles

Checked checkbox AdminLTE Bootstrap in Jquery

November 4, 2014 By Sigit Prasetya Nugroho 7 Comments

Simple create date format validation with jqueryUI

December 21, 2014 By Sigit Prasetya Nugroho Leave a Comment

Create Simple Progress Bar for Fake Online Generator with Jquery

January 10, 2015 By Sigit Prasetya Nugroho Leave a Comment

22+ Coolest Free Jquery Plugin For Premium Theme

October 3, 2015 By Sigit Prasetya Nugroho Leave a Comment

Easy Build Your Anti Copy Paste Plugin

October 6, 2015 By Sigit Prasetya Nugroho Leave a Comment

Popular Tags

adminlte (15) adsense (13) adsense tips (4) affiliate amazon (13) amazon (12) Android (8) angular (16) angular 4 (12) angular 5 (4) asin grabber (3) Bootstrap (27) codeigniter (5) create wordpress theme (5) crud (8) css (6) free wordpress theme (7) google adsense (4) imacros (4) increase traffic (6) jquery (34) laravel (10) laravel 5 (5) learn android (5) modal dialog (5) mysql (6) nodeJs (4) optimize seo (4) pdo (6) php (30) plugin (53) pos (7) Publisher Tips (5) react (3) Reactjs (7) SEO (37) theme (17) tutorial angular (5) tutorial angular 4 (6) tutorial javascript (10) tutorial javascript beginners (4) twitter (3) widget (3) wordpress (18) wordpress plugin (13) XMLRPC (5)




  • About
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms and Conditions

©2021 Seegatesite.com