/
githubmirror
/
material-ui
Обзор
Документация
Войти
/
githubmirror
/
material-ui
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
packages/mui-utils/src/setRef/setRef.ts
25 строк
786 B
Marija Najdova
[utils] Convert all exports to modules (#39882)
26 янв 2024, 05:57
Не верифицирован
26 янв 2024, 05:57
c361a6e
Код
Авторство
О чём код?
import * as React from 'react'; /** * TODO v5: consider making it private * * passes {value} to {ref} * * WARNING: Be sure to only call this inside a callback that is passed as a ref. * Otherwise, make sure to cleanup the previous {ref} if it changes. See * https://github.com/mui/material-ui/issues/13539 * * Useful if you want to expose the ref of an inner component to the public API * while still using it inside the component. * @param ref A ref callback or ref object. If anything falsy, this is a no-op. */ export default function setRef<T>( ref: React.MutableRefObject<T | null> | ((instance: T | null) => void) | null | undefined, value: T | null, ): void { if (typeof ref === 'function') { ref(value); } else if (ref) { ref.current = value; } }