I want to get rid of the warning on StrictMode
for findDOMNode
when using react-transition-group
but I stumbled upon an issue.
My <Slide>
component looks like this:
class Slide extends React.Component {
nodeRef = React.createRef();
render() {
return (
<CSSTransition
in={this.props.in}
timeout={ANIMATION_DURATION}
mountOnEnter={true}
unmountOnExit={true}
classNames={{
enter: "slideEnter",
enterActive: "slideEnterActive",
exit: "slideExit",
exitActive: "slideExitActive"
}}
nodeRef={this.nodeRef}
>
{this.props.children}
</CSSTransition>
);
}
}
It receives a Drawer
element as children, the Drawer
component looks like this:
class Drawer extends React.Component {
render() {
return (
<div className="drawer">
<button onClick={this.props.onClose}>close me</button>{" "}
<div>This is my drawer</div>
</div>
);
}
}
I cannot wrap the children
element with a HTML tag (to attach a ref <div ref={this.nodeRef}>{this.props.children}</div>
because it breaks the animation of the content. (I'm using this for children that are different drawers with position absolute)
I've also tried with cloneElement
but it still doesn't work (with the code from below it behaves like this: 1. in
no animation, 2. out
no animation, 3. in
animation works but I get the warning findDOMNode
so it seems that nodeRef is sent as null, 4. out
animation does not work.
const onlyChild = React.Children.only(this.props.children);
const childWithRef = React.cloneElement(onlyChild, {
ref: this.nodeRef;
});
Is there any solution for this situation? Thanks!
ref: this.nodeRef
instead? If that fixes it, I'll write an answer explaining it. – HepsibahUncaught TypeError: Cannot read property 'baseVal' of undefined at hasClass (hasClass.js?1d84:3) at addClass (addClass.js?0d03:3) at eval (CSSTransition.js?e9c9:13) at Array.forEach (<anonymous>) at addClass (CSSTransition.js?e9c9:12) at CSSTransition.addClass (CSSTransition.js?e9c9:237) at Object.CSSTransition._this.onEnter (CSSTransition.js?e9c9:117) at Transition.performEnter (Transition.js?9b73:262) at Transition.updateStatus (Transition.js?9b73:228) at Transition.componentDidUpdate
– Ahqref: this.nodeRef
, just so my answer doesn't have to address two problems, only the core one. – Hepsibahref
prop through all the components until it gets to the one that uses a DOM element, but I don't like it that much :( – Ahq