通過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
報錯即可完美解決。 ????乛?乛????