From 2776b9266c11c535dbd593a08d8a623566a27f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Wed, 11 Dec 2024 11:04:20 +0800 Subject: [PATCH 1/2] refactor: use rc-util getNodeRef --- package.json | 4 ++-- src/CSSMotion.tsx | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 62e133e..f12b6c7 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "lint": "eslint src/ --ext .tsx,.ts", "now-build": "npm run docs:build", "prepare": "husky install", - "prepublishOnly": "npm run compile && np --yolo --no-publish", + "prepublishOnly": "npm run compile", "prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"", "postpublish": "npm run docs:build && npm run docs:deploy", "start": "dumi dev", @@ -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, + }, + ); } } From 577810369ba3f6592494d60322ec7915d8fe68d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Wed, 11 Dec 2024 11:43:27 +0800 Subject: [PATCH 2/2] chore: back of script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f12b6c7..8112b03 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "lint": "eslint src/ --ext .tsx,.ts", "now-build": "npm run docs:build", "prepare": "husky install", - "prepublishOnly": "npm run compile", + "prepublishOnly": "npm run compile && np --yolo --no-publish", "prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"", "postpublish": "npm run docs:build && npm run docs:deploy", "start": "dumi dev",