react——新版本生命周期函数与旧版本对比

对比图

在这里插入图片描述

1.即将废弃三个生命周期函数,但是也可以用

  1. componentWillMount、componentWillUpdate、componentWillReceiveProps这三个生命周期函数更改名字为:UNSAFE_componentWillMount、UNSAFE_componentWillUpdate、UNSAFE_componentWillReceiveProps(就是前面加上UNSAFE_)
  2. 新版本生命周期函数也兼容老版本的命名,不过控制台会弹出warn警告,警告显示在以后的版本中(18.x的版本),这三个生命周期函数只能用UNSAFE_这种命名方式才能使用。
    在这里插入图片描述

2.新增了两个生命周期函数

  1. getDerivedStateFromProps
  2. getSnapshotBeforeUpdate

猜你喜欢

转载自blog.csdn.net/qq_45895576/article/details/113618374
今日推荐