SlideShare a Scribd company logo
1 of 8
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()

More Related Content

Similar to React js - Component specs and lifecycle

[Cntt] bài giảng java khtn hcm
[Cntt] bài giảng java   khtn hcm[Cntt] bài giảng java   khtn hcm
[Cntt] bài giảng java khtn hcmHong Phuoc Nguyen
 
Ky thuat l.trinh_java
Ky thuat l.trinh_javaKy thuat l.trinh_java
Ky thuat l.trinh_javaLam Man
 
JavaEE Basic_Chapter4: Servlet Nâng Cao
JavaEE Basic_Chapter4: Servlet Nâng CaoJavaEE Basic_Chapter4: Servlet Nâng Cao
JavaEE Basic_Chapter4: Servlet Nâng CaoPhaolo Pham
 
[Cntt] bài giảng lập trình java bkhcm
[Cntt] bài giảng lập trình java   bkhcm[Cntt] bài giảng lập trình java   bkhcm
[Cntt] bài giảng lập trình java bkhcmHong Phuoc Nguyen
 
MÔ HÌNH HÓA & MÔ PHỎNG CÁC CÁC HỆ THỐNG CÔNG NGHIỆP
MÔ HÌNH HÓA & MÔ PHỎNG CÁC CÁC HỆ THỐNG CÔNG NGHIỆPMÔ HÌNH HÓA & MÔ PHỎNG CÁC CÁC HỆ THỐNG CÔNG NGHIỆP
MÔ HÌNH HÓA & MÔ PHỎNG CÁC CÁC HỆ THỐNG CÔNG NGHIỆPLe Nguyen Truong Giang
 
LTJAVA_TV_Slides.ppt
LTJAVA_TV_Slides.pptLTJAVA_TV_Slides.ppt
LTJAVA_TV_Slides.pptssuserf603dc1
 

Similar to React js - Component specs and lifecycle (10)

[Cntt] bài giảng java khtn hcm
[Cntt] bài giảng java   khtn hcm[Cntt] bài giảng java   khtn hcm
[Cntt] bài giảng java khtn hcm
 
[Cntt] all java
[Cntt] all java[Cntt] all java
[Cntt] all java
 
Auto
AutoAuto
Auto
 
Ky thuat l.trinh_java
Ky thuat l.trinh_javaKy thuat l.trinh_java
Ky thuat l.trinh_java
 
JavaEE Basic_Chapter4: Servlet Nâng Cao
JavaEE Basic_Chapter4: Servlet Nâng CaoJavaEE Basic_Chapter4: Servlet Nâng Cao
JavaEE Basic_Chapter4: Servlet Nâng Cao
 
[Cntt] bài giảng lập trình java bkhcm
[Cntt] bài giảng lập trình java   bkhcm[Cntt] bài giảng lập trình java   bkhcm
[Cntt] bài giảng lập trình java bkhcm
 
Data storage Android
Data storage AndroidData storage Android
Data storage Android
 
MÔ HÌNH HÓA & MÔ PHỎNG CÁC CÁC HỆ THỐNG CÔNG NGHIỆP
MÔ HÌNH HÓA & MÔ PHỎNG CÁC CÁC HỆ THỐNG CÔNG NGHIỆPMÔ HÌNH HÓA & MÔ PHỎNG CÁC CÁC HỆ THỐNG CÔNG NGHIỆP
MÔ HÌNH HÓA & MÔ PHỎNG CÁC CÁC HỆ THỐNG CÔNG NGHIỆP
 
LTJAVA_TV_Slides.ppt
LTJAVA_TV_Slides.pptLTJAVA_TV_Slides.ppt
LTJAVA_TV_Slides.ppt
 
Mô phỏng với creo 2.0
Mô phỏng với creo 2.0Mô phỏng với creo 2.0
Mô phỏng với creo 2.0
 

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()