ant-design/components/_util/ref.ts
二货机器人 4680ddc009
fix: Typography warning for ref error (#19074)
* Revert "fix: Typography funtion compoent use Ref console log warning (#19066)"

This reverts commit 3d378f2fd8.

* fix: Typography warning for ref

* not crash on react 15

* still use class if react15

* fix ts define

* clean up

* react 15 lock ref obj

* Use rc-util findDOMNode instead
2019-10-01 01:06:09 -05:00

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);
});
};
}