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