react16.9最新特性之componentWillMount等生命周期即将废弃

这些生命周期钩子已重命名。你仍然可以使用旧版本周期函数,但控制台会报警告。

componentWillMount → UNSAFE_componentWillMount

componentWillReceiveProps → UNSAFE_componentWillReceiveProps

componentWillUpdate → UNSAFE_componentWillUpdate


对于每种 unsafe 的方法,通常有更好的解决方案。
但你可能没有过多时间去迁移或测试这些组件。
在这种情况下,我们建议运行一个自动重命名它们的 codemod 脚本:
cd your_project
npx react-codemod rename-unsafe-lifecycles
原文地址:https://www.cnblogs.com/huihuihero/p/12256750.html