Skip to content

Commit 4e53b49

Browse files
committed
improve readability and add conditional ref prop to element
1 parent 15c5b28 commit 4e53b49

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

packages/core/src/hooks/useTransition.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,18 @@ export function useTransition(
432432
{transitions.map((t, i) => {
433433
const { springs } = changes.get(t) || t.ctrl
434434
const elem: any = render({ ...springs }, t.item, t, i)
435-
return elem && elem.type ? (
435+
436+
if (!elem || !elem.type) return elem
437+
438+
const key = is.str(t.key) || is.num(t.key) ? t.key : t.ctrl.id
439+
const isLegacyReact = React.version < '19.0.0'
440+
441+
return (
436442
<elem.type
437443
{...elem.props}
438-
key={is.str(t.key) || is.num(t.key) ? t.key : t.ctrl.id}
439-
ref={React.version < '19.0.0' ? elem.ref : elem.props.ref}
444+
key={key}
445+
{...(isLegacyReact && { ref: elem.ref })}
440446
/>
441-
) : (
442-
elem
443447
)
444448
})}
445449
</>

0 commit comments

Comments
 (0)