UNPKG

1.03 kBJavaScriptView Raw
1function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
2
3function createRef() {
4 var func = function func(node) {
5 func.current = node;
6 };
7
8 return func;
9}
10
11export function fillRef(ref, node) {
12 if (typeof ref === 'function') {
13 ref(node);
14 } else if (_typeof(ref) === 'object' && ref && 'current' in ref) {
15 ref.current = node;
16 }
17}
18/**
19 * Merge refs into one ref function to support ref passing.
20 */
21
22export function composeRef() {
23 for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
24 refs[_key] = arguments[_key];
25 }
26
27 return function (node) {
28 refs.forEach(function (ref) {
29 fillRef(ref, node);
30 });
31 };
32}
33export default createRef;
\No newline at end of file