diff --git a/src/useRTGTransitionProps.ts b/src/useRTGTransitionProps.ts index 30ddef5..9428196 100644 --- a/src/useRTGTransitionProps.ts +++ b/src/useRTGTransitionProps.ts @@ -4,6 +4,7 @@ import { TransitionProps as RTGTransitionProps, TransitionStatus, } from 'react-transition-group/Transition'; +import { getReactVersion } from './utils'; export type TransitionProps = RTGTransitionProps & { children: @@ -32,10 +33,14 @@ export default function useRTGTransitionProps({ children, ...props }: TransitionProps) { + const { major } = getReactVersion(); + const childRef = + major >= 19 ? (children as any).props.ref : (children as any).ref; + const nodeRef = useRef(null); const mergedRef = useMergedRefs( nodeRef, - typeof children === 'function' ? null : (children as any).ref, + typeof children === 'function' ? null : childRef, ); const normalize = diff --git a/src/utils.ts b/src/utils.ts index fcd515b..1eda92f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,14 @@ -/* eslint-disable import/prefer-default-export */ +import * as React from 'react'; + export function isEscKey(e: KeyboardEvent) { return e.code === 'Escape' || e.keyCode === 27; } + +export function getReactVersion() { + const parts = React.version.split('.'); + return { + major: +parts[0], + minor: +parts[1], + patch: +parts[2], + }; +}