Skip to content

Commit

Permalink
refactor: use rc-util getNodeRef (#57)
Browse files Browse the repository at this point in the history
* refactor: use rc-util getNodeRef

* chore: back of script
  • Loading branch information
zombieJ authored Dec 11, 2024
1 parent 7efe95d commit 9f4c75d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"dependencies": {
"@babel/runtime": "^7.11.1",
"classnames": "^2.2.1",
"rc-util": "^5.43.0"
"rc-util": "^5.44.0"
},
"devDependencies": {
"@rc-component/father-plugin": "^1.0.1",
Expand Down
13 changes: 8 additions & 5 deletions src/CSSMotion.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable react/default-props-match-prop-types, react/no-multi-comp, react/prop-types */
import classNames from 'classnames';
import findDOMNode from 'rc-util/lib/Dom/findDOMNode';
import { fillRef, supportRef } from 'rc-util/lib/ref';
import { fillRef, getNodeRef, supportRef } from 'rc-util/lib/ref';
import * as React from 'react';
import { useRef } from 'react';
import { Context } from './context';
Expand Down Expand Up @@ -233,12 +233,15 @@ export function genCSSMotion(config: CSSMotionConfig) {

// Auto inject ref if child node not have `ref` props
if (React.isValidElement(motionChildren) && supportRef(motionChildren)) {
const { ref: originNodeRef } = motionChildren as any;
const originNodeRef = getNodeRef(motionChildren);

if (!originNodeRef) {
motionChildren = React.cloneElement<any>(motionChildren, {
ref: setNodeRef,
});
motionChildren = React.cloneElement(
motionChildren as React.ReactElement,
{
ref: setNodeRef,
},
);
}
}

Expand Down

0 comments on commit 9f4c75d

Please sign in to comment.