SlideShare a Scribd company logo
Component Specs and Lifecycle
1. Component Specifications
• render
• getInitialState
• getDefaultProps
• propTypes
• Mounting
• Updating
• Unmounting
2. Lifecycle Method
• mixins
• statics
• displayName
1. Component Specifications
render()
- The render() method is required
- The render() function should be pure
getInitialState()
- Invoked once before the component is mounted
getDefaultProps()
- Invoked once and cached when the class is created
- This method is invoked before any instances are created
and thus cannot rely on this.props
1. Component Specifications
propTypes
‒ The propTypes object allows you to validate props being
passed to your components.
mixins[]
‒ The mixins array allows you to use mixins to share
behavior among multiple components.
statics {}
‒ The statics object allows you to define static methods
that can be called on the component class.
2. Lifecycle Methods
Mounting:
1. componentWillMount
2. componentDidMount
Updating:
1. componentWillReceiveProps
2. shouldComponentUpdate
3. componentWillUpdate
4. componentDidUpdate
Unmounting: componentWillUnmount
Khởi tạo component
1. Khởi tạo Class (đã thừa kế từ class Component của
React)
2. Khởi tạo giá trị mặc định cho Props (defaultProps)
3. Khởi tạo giá trị mặc định cho State (getInitialState)
4. Gọi hàm componentWillMount()
5. Gọi hàm render()
6. Gọi hàm componentDidMount()
Khi state thay đổi
1. Cập nhật giá trị cho state
2. Gọi hàm shouldComponentUpdate()
3. Gọi hàm componentWillUpdate() (*)
4. Gọi hàm render()
5. Gọi hàm componentDidUpdate()
Khi Props thay đổi
1. Cập nhật giá trị cho props
2. Gọi hàm componentWillReceiveProps()
3. Gọi hàm shouldComponentUpdate()
4. Gọi hàm componentWillUpdate() – với điều kiện hàm
trên return true
5. Gọi hàm render()
6. Gọi hàm componetDidUpdate()
Ad

Recommended

Lập trình web với các công nghệ phổ biến
Lập trình web với các công nghệ phổ biến
Son Nguyen
 
ứNg dụng xml
ứNg dụng xml
Son Nguyen
 
Understanding Facebook's React.js
Understanding Facebook's React.js
Federico Torre
 
React.js - Wprowadzenie
React.js - Wprowadzenie
Marcin Mieszek
 
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 Testing
Eswara Kumar Palakollu
 
React + Redux Introduction
React + Redux Introduction
Nikolaus Graf
 
React JS and why it's awesome
React JS and why it's awesome
Andrew Hull
 
React js
React js
Jai Santhosh
 
2024 Trend Updates: What Really Works In SEO & Content Marketing
2024 Trend Updates: What Really Works In SEO & Content Marketing
Search Engine Journal
 
Storytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design Process
Chiara Aliotta
 
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
OECD Directorate for Financial and Enterprise Affairs
 
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
 
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 

More Related Content

Featured (20)

2024 Trend Updates: What Really Works In SEO & Content Marketing
2024 Trend Updates: What Really Works In SEO & Content Marketing
Search Engine Journal
 
Storytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design Process
Chiara Aliotta
 
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
OECD Directorate for Financial and Enterprise Affairs
 
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
 
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
2024 Trend Updates: What Really Works In SEO & Content Marketing
2024 Trend Updates: What Really Works In SEO & Content Marketing
Search Engine Journal
 
Storytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design Process
Chiara Aliotta
 
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
 
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 

React js - Component specs and lifecycle

  • 2. 1. Component Specifications • render • getInitialState • getDefaultProps • propTypes • Mounting • Updating • Unmounting 2. Lifecycle Method • mixins • statics • displayName
  • 3. 1. Component Specifications render() - The render() method is required - The render() function should be pure getInitialState() - Invoked once before the component is mounted getDefaultProps() - Invoked once and cached when the class is created - This method is invoked before any instances are created and thus cannot rely on this.props
  • 4. 1. Component Specifications propTypes ‒ The propTypes object allows you to validate props being passed to your components. mixins[] ‒ The mixins array allows you to use mixins to share behavior among multiple components. statics {} ‒ The statics object allows you to define static methods that can be called on the component class.
  • 5. 2. Lifecycle Methods Mounting: 1. componentWillMount 2. componentDidMount Updating: 1. componentWillReceiveProps 2. shouldComponentUpdate 3. componentWillUpdate 4. componentDidUpdate Unmounting: componentWillUnmount
  • 6. Khởi tạo component 1. Khởi tạo Class (đã thừa kế từ class Component của React) 2. Khởi tạo giá trị mặc định cho Props (defaultProps) 3. Khởi tạo giá trị mặc định cho State (getInitialState) 4. Gọi hàm componentWillMount() 5. Gọi hàm render() 6. Gọi hàm componentDidMount()
  • 7. Khi state thay đổi 1. Cập nhật giá trị cho state 2. Gọi hàm shouldComponentUpdate() 3. Gọi hàm componentWillUpdate() (*) 4. Gọi hàm render() 5. Gọi hàm componentDidUpdate()
  • 8. Khi Props thay đổi 1. Cập nhật giá trị cho props 2. Gọi hàm componentWillReceiveProps() 3. Gọi hàm shouldComponentUpdate() 4. Gọi hàm componentWillUpdate() – với điều kiện hàm trên return true 5. Gọi hàm render() 6. Gọi hàm componetDidUpdate()