【发布时间】:2020-05-11 20:48:07
【问题描述】:
我不知道为什么,但我在运行 React 应用程序时看到以下警告:
react-dom.development.js:12357 Warning: componentWillMount has been renamed, and is not recommended for use. See *documentation* 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.
Please update the following components: SideEffect(NullComponent)
我很困惑,因为我没有使用这种生命周期方法。相反,我在我的代码中使用了 useEffect、useMemo 和 useState 挂钩。我希望我有办法摆脱这个警告。
【问题讨论】:
-
您是否在此组件中使用了其他依赖项?也请分享您的组件代码。
标签: reactjs react-hooks react-functional-component