小编Gor*_*995的帖子

带有 CSSTransition 组件的 findDOMNode 警告

“反应”:“^16.13.1”“反应转换组”:“^4.3.0”

  <React.StrictMode>
    <Router>
        <App />
    </Router>
  </React.StrictMode>
Run Code Online (Sandbox Code Playgroud)

嗨,大家好。

我遇到了 findDOMNode 警告,但在互联网上找不到正确的解决方案。

index.js:1 警告:在 StrictMode 中不推荐使用 findDOMNode。findDOMNode 传递了一个 Transition 实例,它在 StrictMode 内...

这个例子是我从off docs here复制的,点击按钮,出现了同样的错误。

const Toolbar = (props) => {
    const [inProp, setInProp] = useState(false);
    return (
        <div>
            <CSSTransition in={inProp} timeout={200} classNames="my-node">
                <div>
                    {"I'll receive my-node-* classes"}
                </div>
            </CSSTransition>
            <button type="button" onClick={() => setInProp(true)}>
                Click to Enter
            </button>
        </div>
    )
};
Run Code Online (Sandbox Code Playgroud)

来自互联网的解决方案建议尝试 createRef(我使用了 usePef 钩子),但是使用 Transitions,它不起作用。

似乎 React.StrictMode 会抛出这样的警告,直到这个库的补丁被合并,但仍然没有看到创建的问题

对于如何解决问题的任何帮助或建议,我将不胜感激

strict-mode reactjs deprecation-warning react-component react-ref

5
推荐指数
1
解决办法
1993
查看次数