SlideShare uma empresa Scribd logo
1 de 22
Baixar para ler offline
Optimizing your use of React
Component Lifecycle Methods
- Why,When,How
By
Shedrack Akintayo
About Me
• Software developer at Legal
Robot
• Do all things Frontend with
JavaScript
• Student in college
• Lover of CSS
• Foodie
• Noisemaker
coder_blvck hacktivist123
Overview
• What are React Lifecycle methods
• Explanation of all the important Lifecycle methods.
• Why do we need to optimize our use of React Lifecycle
methods.
• When do we need to use React Lifecycle methods.
• Pure Components
• Why do we need pure components
• When do we need pure components
What are React Lifecycle methods
Every Component in your React App is going to go through a
lifecycle.
React lifecycle methods is categorized into three with different
methods under each category:
• Mounting
• Updating
• Unmounting
Mounting
This is when your component is first created or when it first
mounts the DOM.
Under the Mounting category we have;
• constructor()
• getDerivedStateFromProps()
• render()
• componentDidMount()
constructor()
constructor(props) {
super(props);
this.state = {};
}
Øperform any initial setup
Øcalled once per mounted component
Øinitialize state
ØMust call super(props)
getDerievedStateFromProps()
It enables a component to update it's internal state as the results
are changing in our props.
render()
This is where react takes out JSX code and prepares it to be
rendered to the DOM.
It's the only one required lifecycle method in a component,and
whe called it will generally return some form of JSX.
componentDidMount()
componentDidMount() is invoked immediately after a component is
mounted (inserted into the tree). Initialization that requires DOM nodes
should go here. If you need to load data from a remote endpoint, this is a
good place to instantiate the network request.
Updating
An update can be caused by changes to props or state,
Under the Updating Category we have:
• shouldComponentUpdate()
• render()
• componentDidUpdate()
shouldComponentUpdate()
This receives the next props and the next state. An alternative to
this is to use pure components.
componentDidUpdate()
• componentDidUpdate() is invoked immediately after updating occurs.
This method is not called for the initial render.
• This is also a good place to do network requests as long as you
compare the current props to previous props (e.g. a network request
may not be necessary if the props have not changed).
Unmounting
This method is called when a component is being removed from
the DOM, the method under it include:
• componentWillUnmount()
componentWillUnmount()
This method is invoked immediately a component is being
removed or destroyed from the DOM. You can Perform any
necessary cleanup in this method, such as invalidating timers, canceling
network requests, or cleaning up any subscriptions that were created
in componentDidMount().
Why do we need to optimize our use of
React Lifecycle methods
The main reason we need to optimize our use of React Lifecycle
methods is because:
• It lets us control what happens when each tiny section of our UI
renders, updates, thinks about re-rendering, and then
disappears entirely.
• It is important and necessary
• It Increases performance and Load time.
When do we need to use React
Component Lifecycle methods
It’s really necessary to use React Component lifecycle methods
• We use componentWillMount most times for App configuration in the root
component
• We use componentDidMount when starting AJAX calls to load in data for
our component.
• We use shouldComponentUpdate when we need to control exactly
when our component should re-render
• We use componentDidUpdate when we need to update the DOM in
response to prop or state changes
• We use componentWillUnmount when we need to clean up useless
code from our component
Pure Components
Pure components are the simplest, fastest components we can write.
They are easy to write, simple to reason about, and the quickest
component we can write.
Why do we need Pure Components
• The usage of Pure Component gives a considerable increase in
performance because it reduces the number of render operation in
the application.
• A Pure component can replace a component that only has
a render function. Instead of making a full-blown component just to
render some content to the screen, we can create a pure one instead.
• It’s simple to write, fast and very understandable
When do we need Pure components
• in cases where you want to use lifecycle methods of Component then
we have to use Pure Components as stateless components don't have
lifecycle methods.
• In cases where you want to avoid re-rendering previous API requests
to the DOM
DEMO CODE
Visit:
https://github.com/hacktivist123/React-Component-lifecycle
References and Additional Resources
• https://reactjs.org/docs/react-component.html
• http://projects.wojtekmaj.pl/react-lifecycle-methods-diagram/
• https://engineering.musefind.com/react-lifecycle-methods-how-
and-when-to-use-them-2111a1b692b1
• https://tylermcginnis.com/an-introduction-to-life-cycle-events-in-
react-js/
Thank You!!!!!
coder_blvck hacktivist123

Mais conteúdo relacionado

Mais procurados

Connecting Connect with Spring Boot
Connecting Connect with Spring BootConnecting Connect with Spring Boot
Connecting Connect with Spring BootVincent Kok
 
Unquoted service path exploitation
Unquoted service path exploitationUnquoted service path exploitation
Unquoted service path exploitationDhruv Sharma
 
WSO2 Test Automation Framework : Approach and Adoption
WSO2 Test Automation Framework : Approach and AdoptionWSO2 Test Automation Framework : Approach and Adoption
WSO2 Test Automation Framework : Approach and AdoptionWSO2
 
Microservices Platform with Spring Boot, Spring Cloud Config, Spring Cloud Ne...
Microservices Platform with Spring Boot, Spring Cloud Config, Spring Cloud Ne...Microservices Platform with Spring Boot, Spring Cloud Config, Spring Cloud Ne...
Microservices Platform with Spring Boot, Spring Cloud Config, Spring Cloud Ne...Tin Linn Soe
 
White paper mbre_en
White paper mbre_enWhite paper mbre_en
White paper mbre_enVisioneerUG
 
Running mule as worker role on azure
Running mule as worker role on azureRunning mule as worker role on azure
Running mule as worker role on azureSon Nguyen
 
Salesforce DUG - Queueable Apex
Salesforce DUG - Queueable ApexSalesforce DUG - Queueable Apex
Salesforce DUG - Queueable ApexAkshay Varu
 
Jenkins Continuous Delivery
Jenkins Continuous DeliveryJenkins Continuous Delivery
Jenkins Continuous DeliveryJadson Santos
 
SpringPeople Introduction to Spring Framework
SpringPeople Introduction to Spring FrameworkSpringPeople Introduction to Spring Framework
SpringPeople Introduction to Spring FrameworkSpringPeople
 
Wap tpresentation (Load testing Tool )
Wap tpresentation (Load testing Tool )Wap tpresentation (Load testing Tool )
Wap tpresentation (Load testing Tool )jagdishdevabhaipatel
 
Spring boot
Spring bootSpring boot
Spring bootsdeeg
 
How to import the agile plm database
How to import the agile plm databaseHow to import the agile plm database
How to import the agile plm databasePLM Mechanic .
 
Springboot and camel
Springboot and camelSpringboot and camel
Springboot and camelDeepak Kumar
 
LoadUI web performance testing tool
LoadUI web performance testing toolLoadUI web performance testing tool
LoadUI web performance testing toolMilind Rupchandani
 
Webservice performance testing with SoapUI
Webservice performance testing with SoapUIWebservice performance testing with SoapUI
Webservice performance testing with SoapUIPhuoc Nguyen
 
Funambol Automated Tests for SyncML Clients
Funambol Automated Tests for SyncML ClientsFunambol Automated Tests for SyncML Clients
Funambol Automated Tests for SyncML ClientsFunambol
 
JMeter JMX Script Creation via BlazeMeter
JMeter JMX Script Creation via BlazeMeterJMeter JMX Script Creation via BlazeMeter
JMeter JMX Script Creation via BlazeMeterRapidValue
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introductionJonathan Holloway
 

Mais procurados (20)

Connecting Connect with Spring Boot
Connecting Connect with Spring BootConnecting Connect with Spring Boot
Connecting Connect with Spring Boot
 
Unquoted service path exploitation
Unquoted service path exploitationUnquoted service path exploitation
Unquoted service path exploitation
 
WSO2 Test Automation Framework : Approach and Adoption
WSO2 Test Automation Framework : Approach and AdoptionWSO2 Test Automation Framework : Approach and Adoption
WSO2 Test Automation Framework : Approach and Adoption
 
Microservices Platform with Spring Boot, Spring Cloud Config, Spring Cloud Ne...
Microservices Platform with Spring Boot, Spring Cloud Config, Spring Cloud Ne...Microservices Platform with Spring Boot, Spring Cloud Config, Spring Cloud Ne...
Microservices Platform with Spring Boot, Spring Cloud Config, Spring Cloud Ne...
 
White paper mbre_en
White paper mbre_enWhite paper mbre_en
White paper mbre_en
 
Running mule as worker role on azure
Running mule as worker role on azureRunning mule as worker role on azure
Running mule as worker role on azure
 
Salesforce DUG - Queueable Apex
Salesforce DUG - Queueable ApexSalesforce DUG - Queueable Apex
Salesforce DUG - Queueable Apex
 
Jenkins Continuous Delivery
Jenkins Continuous DeliveryJenkins Continuous Delivery
Jenkins Continuous Delivery
 
SpringPeople Introduction to Spring Framework
SpringPeople Introduction to Spring FrameworkSpringPeople Introduction to Spring Framework
SpringPeople Introduction to Spring Framework
 
Wap tpresentation (Load testing Tool )
Wap tpresentation (Load testing Tool )Wap tpresentation (Load testing Tool )
Wap tpresentation (Load testing Tool )
 
Spring boot
Spring bootSpring boot
Spring boot
 
How to import the agile plm database
How to import the agile plm databaseHow to import the agile plm database
How to import the agile plm database
 
Springboot and camel
Springboot and camelSpringboot and camel
Springboot and camel
 
LoadUI web performance testing tool
LoadUI web performance testing toolLoadUI web performance testing tool
LoadUI web performance testing tool
 
Webservice performance testing with SoapUI
Webservice performance testing with SoapUIWebservice performance testing with SoapUI
Webservice performance testing with SoapUI
 
Funambol Automated Tests for SyncML Clients
Funambol Automated Tests for SyncML ClientsFunambol Automated Tests for SyncML Clients
Funambol Automated Tests for SyncML Clients
 
JMeter
JMeterJMeter
JMeter
 
JMeter JMX Script Creation via BlazeMeter
JMeter JMX Script Creation via BlazeMeterJMeter JMX Script Creation via BlazeMeter
JMeter JMX Script Creation via BlazeMeter
 
Gatling
Gatling Gatling
Gatling
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
 

Semelhante a Optimizing your use of react life cycles by shedrack akintayo

React.js - The Dawn of Virtual DOM
React.js - The Dawn of Virtual DOMReact.js - The Dawn of Virtual DOM
React.js - The Dawn of Virtual DOMJimit Shah
 
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 TestingEswara Kumar Palakollu
 
React-JS Component Life-cycle Methods
React-JS Component Life-cycle MethodsReact-JS Component Life-cycle Methods
React-JS Component Life-cycle MethodsANKUSH CHAVAN
 
class based component.pptx
class based component.pptxclass based component.pptx
class based component.pptxsaikatsamanta49
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Previewvaluebound
 
O365 Developer Bootcamp NJ 2018 - Material
O365 Developer Bootcamp NJ 2018 - MaterialO365 Developer Bootcamp NJ 2018 - Material
O365 Developer Bootcamp NJ 2018 - MaterialThomas Daly
 
Understanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree TechnologiesUnderstanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree TechnologiesWalking Tree Technologies
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
Angular2 with type script
Angular2 with type scriptAngular2 with type script
Angular2 with type scriptRavi Mone
 
Module Architecture of React-Redux Applications
Module Architecture of React-Redux ApplicationsModule Architecture of React-Redux Applications
Module Architecture of React-Redux ApplicationsAndrii Sliusar
 
Getting started with react & redux
Getting started with react & reduxGetting started with react & redux
Getting started with react & reduxGirish Talekar
 
Angular Application Testing
Angular Application TestingAngular Application Testing
Angular Application TestingTroy Miles
 
Software archiecture lecture08
Software archiecture   lecture08Software archiecture   lecture08
Software archiecture lecture08Luktalja
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react jsStephieJohn
 

Semelhante a Optimizing your use of react life cycles by shedrack akintayo (20)

React.js - The Dawn of Virtual DOM
React.js - The Dawn of Virtual DOMReact.js - The Dawn of Virtual DOM
React.js - The Dawn of Virtual DOM
 
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
 
React-JS Component Life-cycle Methods
React-JS Component Life-cycle MethodsReact-JS Component Life-cycle Methods
React-JS Component Life-cycle Methods
 
Reactjs
Reactjs Reactjs
Reactjs
 
class based component.pptx
class based component.pptxclass based component.pptx
class based component.pptx
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
 
Life Cyrcle.pptx
Life Cyrcle.pptxLife Cyrcle.pptx
Life Cyrcle.pptx
 
O365 Developer Bootcamp NJ 2018 - Material
O365 Developer Bootcamp NJ 2018 - MaterialO365 Developer Bootcamp NJ 2018 - Material
O365 Developer Bootcamp NJ 2018 - Material
 
Understanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree TechnologiesUnderstanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree Technologies
 
React Native Firebase
React Native FirebaseReact Native Firebase
React Native Firebase
 
React workshop
React workshopReact workshop
React workshop
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Angular2 with type script
Angular2 with type scriptAngular2 with type script
Angular2 with type script
 
Module Architecture of React-Redux Applications
Module Architecture of React-Redux ApplicationsModule Architecture of React-Redux Applications
Module Architecture of React-Redux Applications
 
Getting started with react & redux
Getting started with react & reduxGetting started with react & redux
Getting started with react & redux
 
Power Apps for developers
Power Apps for developersPower Apps for developers
Power Apps for developers
 
Angular Application Testing
Angular Application TestingAngular Application Testing
Angular Application Testing
 
Software archiecture lecture08
Software archiecture   lecture08Software archiecture   lecture08
Software archiecture lecture08
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
 

Último

OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedDelhi Call girls
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxalwaysnagaraju26
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456KiaraTiradoMicha
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 

Último (20)

OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 

Optimizing your use of react life cycles by shedrack akintayo

  • 1. Optimizing your use of React Component Lifecycle Methods - Why,When,How By Shedrack Akintayo
  • 2. About Me • Software developer at Legal Robot • Do all things Frontend with JavaScript • Student in college • Lover of CSS • Foodie • Noisemaker coder_blvck hacktivist123
  • 3. Overview • What are React Lifecycle methods • Explanation of all the important Lifecycle methods. • Why do we need to optimize our use of React Lifecycle methods. • When do we need to use React Lifecycle methods. • Pure Components • Why do we need pure components • When do we need pure components
  • 4. What are React Lifecycle methods Every Component in your React App is going to go through a lifecycle. React lifecycle methods is categorized into three with different methods under each category: • Mounting • Updating • Unmounting
  • 5. Mounting This is when your component is first created or when it first mounts the DOM. Under the Mounting category we have; • constructor() • getDerivedStateFromProps() • render() • componentDidMount()
  • 6. constructor() constructor(props) { super(props); this.state = {}; } Øperform any initial setup Øcalled once per mounted component Øinitialize state ØMust call super(props)
  • 7. getDerievedStateFromProps() It enables a component to update it's internal state as the results are changing in our props.
  • 8. render() This is where react takes out JSX code and prepares it to be rendered to the DOM. It's the only one required lifecycle method in a component,and whe called it will generally return some form of JSX.
  • 9. componentDidMount() componentDidMount() is invoked immediately after a component is mounted (inserted into the tree). Initialization that requires DOM nodes should go here. If you need to load data from a remote endpoint, this is a good place to instantiate the network request.
  • 10. Updating An update can be caused by changes to props or state, Under the Updating Category we have: • shouldComponentUpdate() • render() • componentDidUpdate()
  • 11. shouldComponentUpdate() This receives the next props and the next state. An alternative to this is to use pure components.
  • 12. componentDidUpdate() • componentDidUpdate() is invoked immediately after updating occurs. This method is not called for the initial render. • This is also a good place to do network requests as long as you compare the current props to previous props (e.g. a network request may not be necessary if the props have not changed).
  • 13. Unmounting This method is called when a component is being removed from the DOM, the method under it include: • componentWillUnmount()
  • 14. componentWillUnmount() This method is invoked immediately a component is being removed or destroyed from the DOM. You can Perform any necessary cleanup in this method, such as invalidating timers, canceling network requests, or cleaning up any subscriptions that were created in componentDidMount().
  • 15. Why do we need to optimize our use of React Lifecycle methods The main reason we need to optimize our use of React Lifecycle methods is because: • It lets us control what happens when each tiny section of our UI renders, updates, thinks about re-rendering, and then disappears entirely. • It is important and necessary • It Increases performance and Load time.
  • 16. When do we need to use React Component Lifecycle methods It’s really necessary to use React Component lifecycle methods • We use componentWillMount most times for App configuration in the root component • We use componentDidMount when starting AJAX calls to load in data for our component. • We use shouldComponentUpdate when we need to control exactly when our component should re-render • We use componentDidUpdate when we need to update the DOM in response to prop or state changes • We use componentWillUnmount when we need to clean up useless code from our component
  • 17. Pure Components Pure components are the simplest, fastest components we can write. They are easy to write, simple to reason about, and the quickest component we can write.
  • 18. Why do we need Pure Components • The usage of Pure Component gives a considerable increase in performance because it reduces the number of render operation in the application. • A Pure component can replace a component that only has a render function. Instead of making a full-blown component just to render some content to the screen, we can create a pure one instead. • It’s simple to write, fast and very understandable
  • 19. When do we need Pure components • in cases where you want to use lifecycle methods of Component then we have to use Pure Components as stateless components don't have lifecycle methods. • In cases where you want to avoid re-rendering previous API requests to the DOM
  • 21. References and Additional Resources • https://reactjs.org/docs/react-component.html • http://projects.wojtekmaj.pl/react-lifecycle-methods-diagram/ • https://engineering.musefind.com/react-lifecycle-methods-how- and-when-to-use-them-2111a1b692b1 • https://tylermcginnis.com/an-introduction-to-life-cycle-events-in- react-js/