4

我在使用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)

如何纠正这个?

4

2 回答 2

6

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')
)
于 2020-04-16T08:03:12.710 回答
5

这可能是来自您正在使用的库的错误,表明 ReactDOM.findDOMNode 函数现在已弃用但它仍然有效(将来可能会被删除)。

在 StrictMode 中,会出现错误,但由于错误,不建议删除 StrictMode最好忽略此错误或通过报告问题与导致此错误的库联系。

仅供参考,这是react-bootstrap 中的一个已知问题。

于 2020-07-13T06:38:55.693 回答