(returnFiber, current, element)
| 13450 | var isArray$1 = Array.isArray; |
| 13451 | |
| 13452 | function coerceRef(returnFiber, current, element) { |
| 13453 | var mixedRef = element.ref; |
| 13454 | |
| 13455 | if (mixedRef !== null && typeof mixedRef !== 'function' && typeof mixedRef !== 'object') { |
| 13456 | { |
| 13457 | // TODO: Clean this up once we turn on the string ref warning for |
| 13458 | // everyone, because the strict mode case will no longer be relevant |
| 13459 | if ((returnFiber.mode & StrictMode || warnAboutStringRefs) && // We warn in ReactElement.js if owner and self are equal for string refs |
| 13460 | // because these cannot be automatically converted to an arrow function |
| 13461 | // using a codemod. Therefore, we don't have to warn about string refs again. |
| 13462 | !(element._owner && element._self && element._owner.stateNode !== element._self)) { |
| 13463 | var componentName = getComponentName(returnFiber.type) || 'Component'; |
| 13464 | |
| 13465 | if (!didWarnAboutStringRefs[componentName]) { |
| 13466 | { |
| 13467 | error('A string ref, "%s", has been found within a strict mode tree. ' + 'String refs are a source of potential bugs and should be avoided. ' + 'We recommend using useRef() or createRef() instead. ' + 'Learn more about using refs safely here: ' + 'https://fb.me/react-strict-mode-string-ref%s', mixedRef, getStackByFiberInDevAndProd(returnFiber)); |
| 13468 | } |
| 13469 | |
| 13470 | didWarnAboutStringRefs[componentName] = true; |
| 13471 | } |
| 13472 | } |
| 13473 | } |
| 13474 | |
| 13475 | if (element._owner) { |
| 13476 | var owner = element._owner; |
| 13477 | var inst; |
| 13478 | |
| 13479 | if (owner) { |
| 13480 | var ownerFiber = owner; |
| 13481 | |
| 13482 | if (!(ownerFiber.tag === ClassComponent)) { |
| 13483 | { |
| 13484 | throw Error( "Function components cannot have string refs. We recommend using useRef() instead. Learn more about using refs safely here: https://fb.me/react-strict-mode-string-ref" ); |
| 13485 | } |
| 13486 | } |
| 13487 | |
| 13488 | inst = ownerFiber.stateNode; |
| 13489 | } |
| 13490 | |
| 13491 | if (!inst) { |
| 13492 | { |
| 13493 | throw Error( "Missing owner for string ref " + mixedRef + ". This error is likely caused by a bug in React. Please file an issue." ); |
| 13494 | } |
| 13495 | } |
| 13496 | |
| 13497 | var stringRef = '' + mixedRef; // Check if previous string ref matches new string ref |
| 13498 | |
| 13499 | if (current !== null && current.ref !== null && typeof current.ref === 'function' && current.ref._stringRef === stringRef) { |
| 13500 | return current.ref; |
| 13501 | } |
| 13502 | |
| 13503 | var ref = function (value) { |
| 13504 | var refs = inst.refs; |
| 13505 | |
| 13506 | if (refs === emptyRefsObject) { |
| 13507 | // This is a lazy pooled frozen object, so we need to initialize. |
| 13508 | refs = inst.refs = {}; |
| 13509 | } |
no test coverage detected