Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
raw
history blame contribute delete
564 Bytes
export type ReactRef<T> = React.RefCallback<T> | React.MutableRefObject<T>
export function assignRef<T = any>(
ref: ReactRef<T> | null | undefined,
value: T,
) {
if (ref == null) return
if (typeof ref === "function") {
ref(value)
return
}
try {
ref.current = value
} catch (error) {
throw new Error(`Cannot assign value '${value}' to ref '${ref}'`)
}
}
export function mergeRefs<T>(...refs: (ReactRef<T> | null | undefined)[]) {
return (node: T | null) => {
refs.forEach((ref) => {
assignRef(ref, node)
})
}
}