React lifecycle
Method | Side effects1 | State updates2 | Example uses |
---|---|---|---|
<big>Mounting</big> | |||
componentWillMount |
✓ | Constructor 相当于 createClass
|
|
render |
Create and return element(s) | ||
componentDidMount |
✓ | ✓ | DOM操作,网络请求等 |
<big>Updating</big> | |||
componentWillReceiveProps |
✓ | Update state based on changed props
|
|
shouldComponentUpdate |
Compare inputs and determine if render needed | ||
componentWillUpdate |
Set/reset things (eg cached values) before next render | ||
render |
Create and return element(s) | ||
componentDidUpdate |
✓ | ✓ | DOM操作,网络请求等 |
<big>Unmounting</big> | |||
componentWillUnmount |
✓ | DOM操作,网络请求等 |
查看完整资料 请点击这里
- "Side effects" 是指修改变量之外的实例,异步操作,等等。
- "State updates" 是指当前实例(如“this.setState”)。
网友评论