我对React还是很陌生,但遇到了一个问题,我似乎真的找不到任何解决方案...
基本上,我有一个按钮,它会触发一个状态来打开/隐藏模态组件...单击该按钮时,我收到错误消息:
index.js:1警告:StrictMode中不建议使用findDOMNode。 findDOMNode传递了StrictMode内部的Transition实例。而是直接将引用添加到要引用的元素。在此处了解有关安全使用裁判的更多信息:
所以我尝试向我的Modal组件中添加一个引用,但没有用,还尝试用一个引用围绕Modal组件创建包装,也没有帮助吗?
从redux添加connect()之后出现错误-在向组件添加connect()方法之前,我没有得到错误?
代码非常简单:
<div>
<button onClick={toggleTrueFalse}>Click here to open a modal</button>
<CSSTransition
in={showModal}
timeout={300}
classNames="dialog"
unmountOnExit
>
<Modal modalHeaderContent={modalHeaderContent} modalContent={modalContent}/>
</CSSTransition>
</div>
更改模态状态的方法是:
const [showModal, setShowModal] = useState(false);
const toggleTrueFalse = () => setShowModal(!showModal);
我猜测解决方案会很简单,但似乎找不到任何解决方案?
答案 0 :(得分:0)
好的,所以我找到了一个可行的解决方案作为react-transition-group的GIThub页面: https://github.com/reactjs/react-transition-group/issues/668