React中使用antd-mobile组件库中的跑马灯组件报错严格模式问题

通过ceact-react-app搭建的React项目,在使用antd-mobile组件库中的Carousel(跑马灯)组件时,报如下错误:
在这里插入图片描述
Warning: A string ref, “slider”, has been found within a strict mode tree. String refs are a source of potential bugs and should be avoided. We recommend using useRef() or createRef() instead. Learn more about using refs safely here: https://fb.me/react-strict-mode-string-ref

Warning: A string ref, “frame”, has been found within a strict mode tree. String refs are a source of potential bugs and should be avoided. We recommend using useRef() or createRef() instead. Learn more about using refs safely here:
https://fb.me/react-strict-mode-string-ref

(该报错并不影响项目的运行以及跑马灯的效果)

根据报错信息的提示:一个字符串ref,“slider”,已经在一个严格的模式树中找到。说明在React中使用的是严格模式了。

然后自然就想到了 React中的严格模式(Strict Mode)
在这里插入图片描述
根据以上信息,找到项目src目录中的index.js,删除掉该 <React.StrictMode>标签即可。如下图所示:
在这里插入图片描述
报错即可完美解决。 ؏؏☝ᖗ乛◡乛ᖘ☝؏؏

猜你喜欢

转载自blog.csdn.net/it_cgq/article/details/106931152