SlideShare a Scribd company logo
5
Most read
11
Most read
16
Most read
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

PPTX
Thalassemia
FatenAlsadek
 
PPTX
React hooks
Sadhna Rana
 
PDF
Nest.js Introduction
Takuya Tejima
 
PDF
NestJS
Wilson Su
 
PDF
VueJS: The Simple Revolution
Rafael Casuso Romate
 
PPTX
Introduction to Git and GitHub
Bioinformatics and Computational Biosciences Branch
 
PPTX
Introduction to React JS
Arnold Asllani
 
PDF
Reasons to use React Query
javaria javaid
 
Thalassemia
FatenAlsadek
 
React hooks
Sadhna Rana
 
Nest.js Introduction
Takuya Tejima
 
NestJS
Wilson Su
 
VueJS: The Simple Revolution
Rafael Casuso Romate
 
Introduction to React JS
Arnold Asllani
 
Reasons to use React Query
javaria javaid
 

What's hot (20)

PPTX
React hooks
Assaf Gannon
 
PDF
Understanding react hooks
Samundra khatri
 
PPTX
React state
Ducat
 
PDF
Basics of React Hooks.pptx.pdf
Knoldus Inc.
 
PPTX
React hooks
Ramy ElBasyouni
 
PPTX
[Final] ReactJS presentation
洪 鹏发
 
PDF
Introduction to Redux
Ignacio Martín
 
PPTX
React workshop
Imran Sayed
 
PDF
ReactJS presentation
Thanh Tuong
 
PDF
React js
Rajesh Kolla
 
PPTX
React JS - A quick introduction tutorial
Mohammed Fazuluddin
 
PPTX
What is component in reactjs
manojbkalla
 
PPTX
React js
Oswald Campesato
 
PPTX
Introduction to react_js
MicroPyramid .
 
PPTX
Introduction to React JS for beginners
Varun Raj
 
PDF
React and redux
Mystic Coders, LLC
 
PPTX
React js programming concept
Tariqul islam
 
PDF
Introduction to ReactJS
Hoang Long
 
PPTX
Intro to React
Justin Reock
 
PPTX
Its time to React.js
Ritesh Mehrotra
 
React hooks
Assaf Gannon
 
Understanding react hooks
Samundra khatri
 
React state
Ducat
 
Basics of React Hooks.pptx.pdf
Knoldus Inc.
 
React hooks
Ramy ElBasyouni
 
[Final] ReactJS presentation
洪 鹏发
 
Introduction to Redux
Ignacio Martín
 
React workshop
Imran Sayed
 
ReactJS presentation
Thanh Tuong
 
React js
Rajesh Kolla
 
React JS - A quick introduction tutorial
Mohammed Fazuluddin
 
What is component in reactjs
manojbkalla
 
Introduction to react_js
MicroPyramid .
 
Introduction to React JS for beginners
Varun Raj
 
React and redux
Mystic Coders, LLC
 
React js programming concept
Tariqul islam
 
Introduction to ReactJS
Hoang Long
 
Intro to React
Justin Reock
 
Its time to React.js
Ritesh Mehrotra
 
Ad

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

PPTX
lifecycle.pptx
harshsolankurephotos
 
PDF
Optimizing your use of react life cycles by shedrack akintayo
Shedrack Akintayo
 
PPTX
2.React tttttttttttttttttttttttttttttttt
MrVMNair
 
PPTX
React JS: A Secret Preview
valuebound
 
PPTX
Session 03_04-Working with React Native.pptx
VHiu94
 
PDF
React js t6 -lifecycle
Jainul Musani
 
PPTX
class based component.pptx
saikatsamanta49
 
PPTX
Life Cyrcle.pptx
Hương Trà Pé Xjnk
 
PPTX
Life Cycle hooks in VueJs
Squash Apps Pvt Ltd
 
PDF
Understanding React hooks | Walkingtree Technologies
Walking Tree Technologies
 
PDF
20120308 droid4me-paug presentation
Paris Android User Group
 
PPTX
React Workshop: Core concepts of react
Imran Sayed
 
PDF
Fundamental concepts of react js
StephieJohn
 
PPTX
React and Flux life cycle with JSX, React Router and Jest Unit Testing
Eswara Kumar Palakollu
 
PPTX
Reactjs
Neha Sharma
 
ODP
Android App Development - 07 Threading
Diego Grancini
 
PPTX
Adding a modern twist to legacy web applications
Jeff Durta
 
PDF
[Dec 1 meetup] upgrading microservices
Madhuri Yechuri
 
PPTX
How can you force react components to rerender without calling the set state ppt
BOSC Tech Labs
 
ODP
ReactJS Component Lifecycle hooks with examples
Ravi Mone
 
lifecycle.pptx
harshsolankurephotos
 
Optimizing your use of react life cycles by shedrack akintayo
Shedrack Akintayo
 
2.React tttttttttttttttttttttttttttttttt
MrVMNair
 
React JS: A Secret Preview
valuebound
 
Session 03_04-Working with React Native.pptx
VHiu94
 
React js t6 -lifecycle
Jainul Musani
 
class based component.pptx
saikatsamanta49
 
Life Cyrcle.pptx
Hương Trà Pé Xjnk
 
Life Cycle hooks in VueJs
Squash Apps Pvt Ltd
 
Understanding React hooks | Walkingtree Technologies
Walking Tree Technologies
 
20120308 droid4me-paug presentation
Paris Android User Group
 
React Workshop: Core concepts of react
Imran Sayed
 
Fundamental concepts of react js
StephieJohn
 
React and Flux life cycle with JSX, React Router and Jest Unit Testing
Eswara Kumar Palakollu
 
Reactjs
Neha Sharma
 
Android App Development - 07 Threading
Diego Grancini
 
Adding a modern twist to legacy web applications
Jeff Durta
 
[Dec 1 meetup] upgrading microservices
Madhuri Yechuri
 
How can you force react components to rerender without calling the set state ppt
BOSC Tech Labs
 
ReactJS Component Lifecycle hooks with examples
Ravi Mone
 
Ad

Recently uploaded (20)

PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PPT
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
PPTX
Coupa-Overview _Assumptions presentation
annapureddyn
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Doc9.....................................
SofiaCollazos
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
Coupa-Overview _Assumptions presentation
annapureddyn
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 

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.