UNPKG

1.07 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8exports.default = void 0;
9
10var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
12/**
13 * The function that correctly handles passing refs.
14 *
15 * @param ref An ref object or function
16 * @param node A node that should be passed by ref
17 */
18var handleRef = function handleRef(ref, node) {
19 if (process.env.NODE_ENV !== 'production') {
20 if (typeof ref === 'string') {
21 throw new Error('We do not support refs as string, this is a legacy API and will be likely to be removed in one of the future releases of React.');
22 }
23 }
24
25 if (typeof ref === 'function') {
26 ref(node);
27 return;
28 }
29
30 if (ref !== null && (0, _typeof2.default)(ref) === 'object') {
31 // The `current` property is defined as readonly, however it's a valid way because
32 // `ref` is a mutable object
33 ;
34 ref.current = node;
35 }
36};
37
38var _default = handleRef;
39exports.default = _default;
\No newline at end of file