From 9f4c75de703353d7015483c3799a0db8340fd9d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E7=88=B1=E5=90=83=E7=99=BD=E8=90=9D?= =?UTF-8?q?=E5=8D=9C?= Date: Wed, 11 Dec 2024 11:47:03 +0800 Subject: [PATCH] refactor: use rc-util getNodeRef (#57) * refactor: use rc-util getNodeRef * chore: back of script --- package.json | 2 +- src/CSSMotion.tsx | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 62e133e..8112b03 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/CSSMotion.tsx b/src/CSSMotion.tsx index bff0e6c..5660e20 100644 --- a/src/CSSMotion.tsx +++ b/src/CSSMotion.tsx @@ -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'; @@ -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(motionChildren, { - ref: setNodeRef, - }); + motionChildren = React.cloneElement( + motionChildren as React.ReactElement, + { + ref: setNodeRef, + }, + ); } }