React 18 使用antd的message,notification组件报错createRoot warning

react版本:18.2

antd版本:4.19

报错:Use createRoot instead" occurs because the ReactDOM.render method has been deprecated. To solve the error, create a root element and use the ReactDOMClient.render method instead. This occurs since the render () method of the react-dom package is considered legacy starting react-dom version 18.

试了antd的4.17版本 4.19版本 4.19.5版本 问题都存在

解决:升级到文档上最新4.x版本:4.24.12

就可以了 不报错了

参考:

升级 React18 后 message, notification两个组件会提示警告 · Issue #34823 · ant-design/ant-design · GitHub

fix: Notification & message throw `createRoot` warning in React 18 by zombieJ · Pull Request #35030 · ant-design/ant-design · GitHub

fix: React 18 use createRoot instead by zombieJ · Pull Request #203 · react-component/notification · GitHub

猜你喜欢

转载自blog.csdn.net/csdn1940879828/article/details/132019536
今日推荐