mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-05 09:49:57 +08:00
18 lines
404 B
TypeScript
18 lines
404 B
TypeScript
|
import React from 'react';
|
||
|
|
||
|
export function fillRef<T>(ref: React.Ref<T>, node: T) {
|
||
|
if (typeof ref === 'function') {
|
||
|
ref(node);
|
||
|
} else if (typeof ref === 'object' && ref && 'current' in ref) {
|
||
|
(ref as any).current = node;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export function composeRef<T>(...refs: React.Ref<T>[]): React.Ref<T> {
|
||
|
return (node: T) => {
|
||
|
refs.forEach(ref => {
|
||
|
fillRef(ref, node);
|
||
|
});
|
||
|
};
|
||
|
}
|