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

通过ceact-react-app搭建的React项目,在使用antd-mobile组件库中的Carousel(跑马灯)组件时,报如下错误:

image

<font color="red">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:</font > https://fb.me/react-strict-mode-string-ref
<font color="red">
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: </font > https://fb.me/react-strict-mode-string-ref

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

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

然后自然就想到了 React中的严格模式(Strict Mode)

image

根据以上信息,找到项目src目录中的index.js,删除掉该 <React.StrictMode>标签即可。如下图所示:
image

报错即可完美解决。 ؏؏☝ᖗ乛◡乛ᖘ☝؏؏

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。