Skip to content
{}

基础知识 - 生命周期

总结

1. 性能提升

两种方案 shouldComponentUpdate PureComponent

2. 周期替代

  1. getDerivedStateFromPropscomponentDidUpdate 配套使用 ,可以替代 componentWillMount componentWillReceiveProps
  1. getSnapshotBeforeUpdate 可以替代 componentWillUpdate

3. 新老周期使用问题

用了新生命周期就不要在用老生命周期了,控制台会报错,所谓 "一山不容二虎"

4. 弃用周期

componentWillMount componentWillUpdata componentWillReceiveProps 都即将被弃用 ,请选择新生命周期来替代,如果你想无视警告,请在生命周期前面拼上UNSAFE_

好好加油吧,少年!