通過(guò)ceact-react-app搭建的React項(xiàng)目屏积,在使用antd-mobile組件庫(kù)中的Carousel(跑馬燈)組件時(shí)空闲,報(bào)如下錯(cuò)誤:
<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
(該報(bào)錯(cuò)并不影響項(xiàng)目的運(yùn)行以及跑馬燈的效果)
根據(jù)報(bào)錯(cuò)信息的提示:一個(gè)字符串ref冷冗,“slider”,已經(jīng)在一個(gè)嚴(yán)格的模式樹(shù)中找到。說(shuō)明在React中使用的是嚴(yán)格模式了裙士。
然后自然就想到了 React中的嚴(yán)格模式(Strict Mode)。
根據(jù)以上信息管毙,找到項(xiàng)目src目錄中的index.js腿椎,刪除掉該 <React.StrictMode>標(biāo)簽即可。如下圖所示:
報(bào)錯(cuò)即可完美解決夭咬。 ????乛?乛????