SlideShare a Scribd company logo
ReactJs Component
Lifecycle Methods
By: Chavan Ankush S.
What is lifecycle methods and why it is
important?
● Around us everything goes through a cycle of taking birth,
growing and at some point of time it will die.
● Consider trees, any software application, yourself, a div
container or UI component in a web browser, each of these
takes birth, grows by getting updates and dies.
● The lifecycle methods are various methods which are invoked
at different phases of the lifecycle of a component.
Four phases of a React component
● The React component goes through the following phases
○ Initialization
○ Mounting
○ Update
○ Unmounting
Visual representation of the phases and
the methods of ReactJs lifecycle.
Initialization
● In this phase the React component prepares for the upcoming
tough journey, by setting up the initial states and default
props, if any.
● The component is setting up the initial state in the constructor,
which can be changed later by using the setState method.
Mounting
● After preparing with basic needs, state and props, our React
Component is ready to mount in the browser DOM.
● This phase gives hook methods for before and after mounting
of components.
● The methods which gets called in this phase are
○ componentWillMount()
○ render()
○ componentDidMount()
Mounting conti…..
● componentWillMount()
○ This method is executed just before the React Component
is about to mount on the DOM.
○ This method is executed once in a lifecycle of a
component and before first render.
○ Usage: This method is used for initializing the states or
props,there is a huge debate going on to merge it with the
constructor.
Mounting conti…..
● render()
○ This method is mounts the component onto the browser.
○ This is a pure method, which means it gives the same
output every time the same input is provided.
Mounting conti…..
● componentDidMount()
○ This this is the hook method which is executed after the
component did mount on the dom.
○ This method is executed once in a lifecycle of a
component and after the first render.
○ As, in this method, we can access the DOM
○ Usage: this is the right method to integrate API
Update
● This phase starts when the react component has taken birth
on the browser and grows by receiving new updates.
● The component can be updated by two ways:
○ sending new props
○ updating the state.
Update Conti…...
● sending new props
○ The methods which gets called in this phase are :
■ componentWillReceiveProps()
■ shouldComponentUpdate()
■ componentWillUpdate()
■ render()
■ componentDidUpdate()
Update Conti…...
● componentWillReceiveProps()
○ This method gets executed when the props have changed
and is not first render.
○ Sometimes state depends on the props, hence whenever
props changes the state should also be synced,This is the
method where it should be done.
○ Usage: This is how the state can be kept synced with the
new props.
Update Conti…...
● shouldComponentUpdate()
○ This method tells the React that when the component
receives new props or state is being updated, should
React re-render or it can skip rendering?
● componentWillUpdate()
○ This method is executed only after the
shouldComponentUpdate() returns true
○ This method is only used to do the preparation for the
upcoming render, similar to componentWillMount() or
constructor.
Update Conti…...
● render()
○ This method is mounts the component onto the browser
● componentDidUpdate()
○ This method is executed when the new updated
component has been updated in the DOM.
○ This method is used to re trigger the third party libraries
used to make sure these libraries also update and reload
themselves.
Update Conti…...
● updating the state
○ The methods which gets called in this phase are :
■ shouldComponentUpdate()
■ componentWillUpdate()
■ render()
■ componentDidUpdate()
Unmounting
● In this phase, the component is not needed and the
component will get unmounted from the DOM.
● The method which is called in this phase :
○ componentWillUnmount()
Unmounting Conti….
● componentWillUnmount
○ This method is the last method in the lifecycle.
○ This is executed just before the component gets removed
from the DOM.
○ Usage: In this method, we do all the cleanups related to
the component.
■ For example, on logout, the user details and all the
auth tokens can be cleared before unmounting the
main component.
Any Question ?
Thank you...

More Related Content

What's hot

ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
Thanh Tuong
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
Knoldus Inc.
 
Reactjs
ReactjsReactjs
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
Tariqul islam
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
Emanuele DelBono
 
React js
React jsReact js
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation洪 鹏发
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_js
MicroPyramid .
 
Intro to React
Intro to ReactIntro to React
Intro to React
Eric Westfall
 
React hooks
React hooksReact hooks
React hooks
Sadhna Rana
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
Varun Raj
 
React hooks
React hooksReact hooks
React hooks
Assaf Gannon
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
valuebound
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
Arno Lordkronos
 
React Native Workshop
React Native WorkshopReact Native Workshop
React Native Workshop
Amazon Web Services
 
Lets make a better react form
Lets make a better react formLets make a better react form
Lets make a better react form
Yao Nien Chung
 
React workshop
React workshopReact workshop
React workshop
Imran Sayed
 
ES6 presentation
ES6 presentationES6 presentation
ES6 presentation
ritika1
 
Introduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace ITIntroduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace IT
namespaceit
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooks
Samundra khatri
 

What's hot (20)

ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
 
Reactjs
ReactjsReactjs
Reactjs
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
 
React js
React jsReact js
React js
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_js
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
React hooks
React hooksReact hooks
React hooks
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
 
React hooks
React hooksReact hooks
React hooks
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
React Native Workshop
React Native WorkshopReact Native Workshop
React Native Workshop
 
Lets make a better react form
Lets make a better react formLets make a better react form
Lets make a better react form
 
React workshop
React workshopReact workshop
React workshop
 
ES6 presentation
ES6 presentationES6 presentation
ES6 presentation
 
Introduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace ITIntroduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace IT
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooks
 

Similar to React-JS Component Life-cycle Methods

lifecycle.pptx
lifecycle.pptxlifecycle.pptx
lifecycle.pptx
harshsolankurephotos
 
Optimizing your use of react life cycles by shedrack akintayo
Optimizing your use of react life cycles by shedrack akintayoOptimizing your use of react life cycles by shedrack akintayo
Optimizing your use of react life cycles by shedrack akintayo
Shedrack Akintayo
 
React js t6 -lifecycle
React js   t6 -lifecycleReact js   t6 -lifecycle
React js t6 -lifecycle
Jainul Musani
 
class based component.pptx
class based component.pptxclass based component.pptx
class based component.pptx
saikatsamanta49
 
Life Cycle hooks in VueJs
Life Cycle hooks in VueJsLife Cycle hooks in VueJs
Life Cycle hooks in VueJs
Squash Apps Pvt Ltd
 
Understanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree TechnologiesUnderstanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree Technologies
Walking Tree Technologies
 
React Workshop: Core concepts of react
React Workshop: Core concepts of reactReact Workshop: Core concepts of react
React Workshop: Core concepts of react
Imran Sayed
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
StephieJohn
 
React and Flux life cycle with JSX, React Router and Jest Unit Testing
React and  Flux life cycle with JSX, React Router and Jest Unit TestingReact and  Flux life cycle with JSX, React Router and Jest Unit Testing
React and Flux life cycle with JSX, React Router and Jest Unit Testing
Eswara Kumar Palakollu
 
Android App Development - 07 Threading
Android App Development - 07 ThreadingAndroid App Development - 07 Threading
Android App Development - 07 Threading
Diego Grancini
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
Jeff Durta
 
[Dec 1 meetup] upgrading microservices
[Dec 1 meetup] upgrading microservices[Dec 1 meetup] upgrading microservices
[Dec 1 meetup] upgrading microservices
Madhuri Yechuri
 
How can you force react components to rerender without calling the set state ppt
How can you force react components to rerender without calling the set state pptHow can you force react components to rerender without calling the set state ppt
How can you force react components to rerender without calling the set state ppt
BOSC Tech Labs
 
ReactJS Component Lifecycle hooks with examples
ReactJS Component Lifecycle hooks with examples ReactJS Component Lifecycle hooks with examples
ReactJS Component Lifecycle hooks with examples
Ravi Mone
 
Mobile Application Development class 006
Mobile Application Development class 006Mobile Application Development class 006
Mobile Application Development class 006
Dr. Mazin Mohamed alkathiri
 
Fundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdfFundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdf
StephieJohn
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native
Eric Deng
 

Similar to React-JS Component Life-cycle Methods (20)

lifecycle.pptx
lifecycle.pptxlifecycle.pptx
lifecycle.pptx
 
Optimizing your use of react life cycles by shedrack akintayo
Optimizing your use of react life cycles by shedrack akintayoOptimizing your use of react life cycles by shedrack akintayo
Optimizing your use of react life cycles by shedrack akintayo
 
React js t6 -lifecycle
React js   t6 -lifecycleReact js   t6 -lifecycle
React js t6 -lifecycle
 
class based component.pptx
class based component.pptxclass based component.pptx
class based component.pptx
 
Life Cyrcle.pptx
Life Cyrcle.pptxLife Cyrcle.pptx
Life Cyrcle.pptx
 
Life Cycle hooks in VueJs
Life Cycle hooks in VueJsLife Cycle hooks in VueJs
Life Cycle hooks in VueJs
 
Understanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree TechnologiesUnderstanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree Technologies
 
20120308 droid4me-paug presentation
20120308 droid4me-paug presentation20120308 droid4me-paug presentation
20120308 droid4me-paug presentation
 
React Workshop: Core concepts of react
React Workshop: Core concepts of reactReact Workshop: Core concepts of react
React Workshop: Core concepts of react
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
 
React and Flux life cycle with JSX, React Router and Jest Unit Testing
React and  Flux life cycle with JSX, React Router and Jest Unit TestingReact and  Flux life cycle with JSX, React Router and Jest Unit Testing
React and Flux life cycle with JSX, React Router and Jest Unit Testing
 
Android App Development - 07 Threading
Android App Development - 07 ThreadingAndroid App Development - 07 Threading
Android App Development - 07 Threading
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
[Dec 1 meetup] upgrading microservices
[Dec 1 meetup] upgrading microservices[Dec 1 meetup] upgrading microservices
[Dec 1 meetup] upgrading microservices
 
How can you force react components to rerender without calling the set state ppt
How can you force react components to rerender without calling the set state pptHow can you force react components to rerender without calling the set state ppt
How can you force react components to rerender without calling the set state ppt
 
ReactJS Component Lifecycle hooks with examples
ReactJS Component Lifecycle hooks with examples ReactJS Component Lifecycle hooks with examples
ReactJS Component Lifecycle hooks with examples
 
Mobile Application Development class 006
Mobile Application Development class 006Mobile Application Development class 006
Mobile Application Development class 006
 
Fundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdfFundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdf
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native
 
Web dynpro
Web dynproWeb dynpro
Web dynpro
 

Recently uploaded

Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 

Recently uploaded (20)

Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 

React-JS Component Life-cycle Methods

  • 2. What is lifecycle methods and why it is important? ● Around us everything goes through a cycle of taking birth, growing and at some point of time it will die. ● Consider trees, any software application, yourself, a div container or UI component in a web browser, each of these takes birth, grows by getting updates and dies. ● The lifecycle methods are various methods which are invoked at different phases of the lifecycle of a component.
  • 3. Four phases of a React component ● The React component goes through the following phases ○ Initialization ○ Mounting ○ Update ○ Unmounting
  • 4. Visual representation of the phases and the methods of ReactJs lifecycle.
  • 5. Initialization ● In this phase the React component prepares for the upcoming tough journey, by setting up the initial states and default props, if any. ● The component is setting up the initial state in the constructor, which can be changed later by using the setState method.
  • 6. Mounting ● After preparing with basic needs, state and props, our React Component is ready to mount in the browser DOM. ● This phase gives hook methods for before and after mounting of components. ● The methods which gets called in this phase are ○ componentWillMount() ○ render() ○ componentDidMount()
  • 7. Mounting conti….. ● componentWillMount() ○ This method is executed just before the React Component is about to mount on the DOM. ○ This method is executed once in a lifecycle of a component and before first render. ○ Usage: This method is used for initializing the states or props,there is a huge debate going on to merge it with the constructor.
  • 8. Mounting conti….. ● render() ○ This method is mounts the component onto the browser. ○ This is a pure method, which means it gives the same output every time the same input is provided.
  • 9. Mounting conti….. ● componentDidMount() ○ This this is the hook method which is executed after the component did mount on the dom. ○ This method is executed once in a lifecycle of a component and after the first render. ○ As, in this method, we can access the DOM ○ Usage: this is the right method to integrate API
  • 10. Update ● This phase starts when the react component has taken birth on the browser and grows by receiving new updates. ● The component can be updated by two ways: ○ sending new props ○ updating the state.
  • 11. Update Conti…... ● sending new props ○ The methods which gets called in this phase are : ■ componentWillReceiveProps() ■ shouldComponentUpdate() ■ componentWillUpdate() ■ render() ■ componentDidUpdate()
  • 12. Update Conti…... ● componentWillReceiveProps() ○ This method gets executed when the props have changed and is not first render. ○ Sometimes state depends on the props, hence whenever props changes the state should also be synced,This is the method where it should be done. ○ Usage: This is how the state can be kept synced with the new props.
  • 13. Update Conti…... ● shouldComponentUpdate() ○ This method tells the React that when the component receives new props or state is being updated, should React re-render or it can skip rendering? ● componentWillUpdate() ○ This method is executed only after the shouldComponentUpdate() returns true ○ This method is only used to do the preparation for the upcoming render, similar to componentWillMount() or constructor.
  • 14. Update Conti…... ● render() ○ This method is mounts the component onto the browser ● componentDidUpdate() ○ This method is executed when the new updated component has been updated in the DOM. ○ This method is used to re trigger the third party libraries used to make sure these libraries also update and reload themselves.
  • 15. Update Conti…... ● updating the state ○ The methods which gets called in this phase are : ■ shouldComponentUpdate() ■ componentWillUpdate() ■ render() ■ componentDidUpdate()
  • 16. Unmounting ● In this phase, the component is not needed and the component will get unmounted from the DOM. ● The method which is called in this phase : ○ componentWillUnmount()
  • 17. Unmounting Conti…. ● componentWillUnmount ○ This method is the last method in the lifecycle. ○ This is executed just before the component gets removed from the DOM. ○ Usage: In this method, we do all the cleanups related to the component. ■ For example, on logout, the user details and all the auth tokens can be cleared before unmounting the main component.