警告:findDOMNode在StrictMode中已弃用,react-redux-notify

时间:2020-03-22 16:55:19

标签: reactjs react-redux notify deprecation-warning strict-mode

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

该如何纠正?

2 个答案:

答案 0 :(得分:5)

index.js中 删除包装器

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

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

答案 1 :(得分:3)

这可能是您正在使用的库中的一个错误,它是您现在已经不赞成使用ReactDOM.findDOMNode函数,但是该函数仍然有效(将来可能会删除)。

在StrictMode中,将显示错误,但由于该错误,不建议删除StrictMode 最好忽略此错误,或者通过报告问题来联系引起此问题的图书馆。

仅供参考,这是react-bootstrap.

中的一个已知问题