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

(該報錯并不影響項目的運行以及跑馬燈的效果)

根據(jù)報錯信息的提示:一個字符串ref,“slider”,已經(jīng)在一個嚴格的模式樹中找到。說明在React中使用的是嚴格模式了。

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

image

根據(jù)以上信息,找到項目src目錄中的index.js,刪除掉該 <React.StrictMode>標簽即可。如下圖所示:
image

報錯即可完美解決。 ????乛?乛????

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容