Skip to content

Commit 9fb85c5

Browse files
committed
refactor: gate auto ref injection by children arity
1 parent c1d0fe6 commit 9fb85c5

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/CSSMotion.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,9 @@ export function genCSSMotion(config: CSSMotionConfig) {
253253
return nextMotionChildren;
254254
}, [idRef.current]) as React.ReactElement;
255255

256-
if (supportNodeRef(motionChildren)) {
256+
const shouldAutoInjectRef = children?.length < 2;
257+
258+
if (shouldAutoInjectRef && supportNodeRef(motionChildren)) {
257259
const originNodeRef = getNodeRef(motionChildren);
258260

259261
if (originNodeRef !== nodeRef) {

src/CSSMotionList.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ export function genCSSMotionList(
174174
}
175175
}}
176176
>
177-
{(props, ref) => children({ ...props, index }, ref)}
177+
{children.length < 2
178+
? props => children({ ...props, index }, undefined as any)
179+
: (props, ref) => children({ ...props, index }, ref)}
178180
</CSSMotion>
179181
);
180182
})}

0 commit comments

Comments
 (0)