|
1. 问题描述
启动服务,发现浏览器控制台报如下warning: VM25 common.bundle.js:36926 Warning: componentWillMount has been renamed, and is not recommended for use. See https://fb.me/react-unsafe-component-lifecycles for details. * Move code with side effects to componentDidMount, and set initial state in the constructor. * Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder. 2. 问题原因 从报错的信息大致可以知道,react部分旧的生命周期(### componentWillMount)在新的版本中(react 17.0以上版本)将会弃用,需要改名字(UNSAFE_componentWillMount)。 由于在代码项目中没有使用componentWillMount生命周期,并且现在react版本还没有出到17.0(2019-11-01),为了不报这个Warning,需要解决此问题。 解决方案: https://segmentfault.com/a/1190000020875617?utm_source=tag-newest |
|
|