首页 > 解决方案 > 警告:在 StrictMode 中不推荐使用 findDOMNode,react-redux-notify

问题描述

我在使用react-redux-notify时收到此警告

index.js:1 Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of CSSTransitionGroupChild which is inside StrictMode. Instead, add a ref directly to the element you want to reference. Learn more about using refs safely here: ---/react-strict-mode-find-node
    in div (created by Notification)
    in Notification (created by Notify)
    in CSSTransitionGroupChild (created by TransitionGroup)
    in div (created by TransitionGroup)
    in TransitionGroup (created by CSSTransitionGroup)
    in CSSTransitionGroup (created by Notify)
    in div (created by Notify)
    in Notify (created by ConnectFunction)
    in ConnectFunction (at App.js:56)
    in div (at App.js:55)
    in Provider (at App.js:54)
    in App (at src/index.js:9)
    in StrictMode (at src/index.js:8)

如何纠正这个?

标签: reactjsreact-reduxdeprecation-warningstrict-modereact-redux-notify

解决方案


index.js 删除 <React.StrictMode> 包装

ReactDOM.render(                                                                              <React.StrictMode>
  <React.StrictMode> //remove this
    <App />
  <React.StrictMode/> //remove this as well.
,
  document.getElementById('root')
)

ReactDOM.render(
      <App />,
      document.getElementById('root')
)

推荐阅读