生命周期函数过期的问题
来源:4-9 React 生命周期函数的使用场景
changzheng
2021-01-24
老师
您好
今天调试课程案例时出现一个警告
react-dom.development.js:67 Warning: componentWillMount has been renamed, and is not recommended for use. See https://reactjs.org/link/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 18.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.
Please update the following components: TodoItem
引入了2个新的生命周期函数
static getDerivedStateFromProps and getSnapshotBeforeUpdate.
能详细讲解 componentWillMount、componentWillReceiveProps、componentWillUpdate会出现哪些问题吗
写回答
1回答
-
目前来说,这些函数还可以用,但是17以后的版本可能就不支持了。这块同学你可以搜索下getDerivedStateFromProps, getSnapshotBeforeUpdate 两个函数的解释,实际上它们能够完全替换下面几个函数的功能。
00
相似问题