SlideShare a Scribd company logo
Do and DoN'T Summary of React Component
Lifecycle Methods
Sunil Mishra
11 May 2020
Agenda
• Do and DON’T List of React Component Lifecycle Methods
constructor
• DO
• Assign the initial state to this.state directly.
• Prepare all class fields and bind functions that will be passed as callbacks.
• DON’T
• Cause any side effects (AJAX calls, subscriptions etc.)
• Call setState()
• Copy props into state (only use this pattern if you intentionally want to ignore prop
updates)
render () Method
• DO
• Return a valid javascript value
• The render() function should be pure.
• DON’T
• Call setState()
componentDidMount() Method
• DO
• Setup subscriptions
• Network requests
• May setState() immediately (Use this pattern with caution, because it
often cause performance issues).
• DON’T
• Call this.setState as it will result in a re-render.
componentDidUpdate() Method
• DO
• Network requests incase if the props have changed otherwise not
required.
• May setState() immediately in componentDidUpdate(), but it must be
wrapped in a condition.
• DON’T
• Call this.setState as it will result in a re-render.
shouldComponentUpdate() Method
• DO
• Remove any timers or listeners created in the life span of the
component
• DON’T
• Call this.setState, start new listeners or timers.
static getDerivedStateFromError() Method
• DO
• Catch errors and return them as state objects.
• Handle fallback rendering.
• DON’T
• Cause any side effects.
componentDidCatch() Method
• DO
• Side effects are permitted
• Log errors
• DON’T
• Render a fallback UI with componentDidCatch() by calling setState.
Contact Us
Email Id:
sunilmishra18@gmail.com
Facebook:
https://www.facebook.com/coolmonktechie18
Blogger:
https://coolmonktechie.blogspot.com/
Twitter:
@sunilmishra18
Thank You !! 😊😊😊

More Related Content

PPTX
React-JS Component Life-cycle Methods
PDF
Understanding react hooks
PPTX
React hooks
PPTX
React hooks
PDF
React state management with Redux and MobX
PDF
React js use contexts and useContext hook
PDF
Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5
PDF
MobX for dummies
React-JS Component Life-cycle Methods
Understanding react hooks
React hooks
React hooks
React state management with Redux and MobX
React js use contexts and useContext hook
Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5
MobX for dummies

What's hot (18)

PDF
Introduction to React Hooks
PDF
Getting Started with NgRx (Redux) Angular
PDF
Plain react, hooks and/or Redux ?
PPTX
React hooks
PPTX
React tips
PPTX
Creating global functions
PDF
Redux data flow with angular 2
PDF
Making react part of something greater
ODP
Drupal 7 rules module
PDF
State Models for React with Redux
ODP
Gatling
PPTX
React.js - The Dawn of Virtual DOM
PDF
RxJava@Android
PDF
React hooks Episode #1: An introduction.
PPTX
Introduction to RxJava on Android
PDF
Using ReasonML For Your Next JavaScript Project
PPTX
PDF
Workshop 22: React-Redux Middleware
Introduction to React Hooks
Getting Started with NgRx (Redux) Angular
Plain react, hooks and/or Redux ?
React hooks
React tips
Creating global functions
Redux data flow with angular 2
Making react part of something greater
Drupal 7 rules module
State Models for React with Redux
Gatling
React.js - The Dawn of Virtual DOM
RxJava@Android
React hooks Episode #1: An introduction.
Introduction to RxJava on Android
Using ReasonML For Your Next JavaScript Project
Workshop 22: React-Redux Middleware
Ad

Similar to Do and Don't summary of React Component Lifecycle Methods (20)

PPTX
React and Flux life cycle with JSX, React Router and Jest Unit Testing
PDF
Optimizing your use of react life cycles by shedrack akintayo
PPTX
React workshop
PPTX
2.React tttttttttttttttttttttttttttttttt
PPTX
React JS Workings Exercises Extra Classes
PPTX
[Final] ReactJS presentation
PPTX
Advance java session 5
PDF
Angular Application Testing
PDF
Understanding Facebook's React.js
PDF
MobiConf 2018 | Room: an SQLite object mapping library
PPTX
React - Start learning today
PDF
Building High-Performance Force.com Applications in React
PPTX
Introduction to React JS for beginners
PPTX
class based component.pptx
PPTX
React Workshop: Core concepts of react
PPTX
Reactjs
PDF
Module Architecture of React-Redux Applications
PDF
React for Re-use: Creating UI Components with Confluence Connect
PPTX
Database connect
PPTX
21CS642 Module 5 JDBC PPT.pptx VI SEM CSE Students
React and Flux life cycle with JSX, React Router and Jest Unit Testing
Optimizing your use of react life cycles by shedrack akintayo
React workshop
2.React tttttttttttttttttttttttttttttttt
React JS Workings Exercises Extra Classes
[Final] ReactJS presentation
Advance java session 5
Angular Application Testing
Understanding Facebook's React.js
MobiConf 2018 | Room: an SQLite object mapping library
React - Start learning today
Building High-Performance Force.com Applications in React
Introduction to React JS for beginners
class based component.pptx
React Workshop: Core concepts of react
Reactjs
Module Architecture of React-Redux Applications
React for Re-use: Creating UI Components with Confluence Connect
Database connect
21CS642 Module 5 JDBC PPT.pptx VI SEM CSE Students
Ad

Recently uploaded (20)

PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
Modernizing your data center with Dell and AMD
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPT
Teaching material agriculture food technology
PDF
cuic standard and advanced reporting.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Machine learning based COVID-19 study performance prediction
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Big Data Technologies - Introduction.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
Modernizing your data center with Dell and AMD
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Advanced Soft Computing BINUS July 2025.pdf
Unlocking AI with Model Context Protocol (MCP)
The Rise and Fall of 3GPP – Time for a Sabbatical?
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Per capita expenditure prediction using model stacking based on satellite ima...
Dropbox Q2 2025 Financial Results & Investor Presentation
Teaching material agriculture food technology
cuic standard and advanced reporting.pdf
Electronic commerce courselecture one. Pdf
Machine learning based COVID-19 study performance prediction
The AUB Centre for AI in Media Proposal.docx
Big Data Technologies - Introduction.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
NewMind AI Weekly Chronicles - August'25 Week I

Do and Don't summary of React Component Lifecycle Methods