/
githubmirror
/
material-ui
Обзор
Документация
Войти
/
githubmirror
/
material-ui
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
packages/mui-utils/src/getReactElementRef/getReactElementRef.ts
18 строк
769 B
Aarón García Hervás
[utils] Make getReactElementRef React 19 compatible (#44034)
08 окт 2024, 10:53
Не верифицирован
08 окт 2024, 10:53
edefd06
Код
Авторство
О чём код?
import * as React from 'react'; /** * Returns the ref of a React element handling differences between React 19 and older versions. * It will throw runtime error if the element is not a valid React element. * * @param element React.ReactElement * @returns React.Ref<any> | null */ export default function getReactElementRef(element: React.ReactElement): React.Ref<any> | null { // 'ref' is passed as prop in React 19, whereas 'ref' is directly attached to children in older versions if (parseInt(React.version, 10) >= 19) { return (element?.props as any)?.ref || null; } // @ts-expect-error element.ref is not included in the ReactElement type // https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/70189 return element?.ref || null; }