(returnFiber, current, element)
| 17010 | var isArray$1 = Array.isArray; |
| 17011 | |
| 17012 | function coerceRef(returnFiber, current, element) { |
| 17013 | var mixedRef = element.ref; |
| 17014 | |
| 17015 | if (mixedRef !== null && typeof mixedRef !== 'function' && typeof mixedRef !== 'object') { |
| 17016 | { |
| 17017 | // TODO: Clean this up once we turn on the string ref warning for |
| 17018 | // everyone, because the strict mode case will no longer be relevant |
| 17019 | if ((returnFiber.mode & StrictMode || warnAboutStringRefs) && // We warn in ReactElement.js if owner and self are equal for string refs |
| 17020 | // because these cannot be automatically converted to an arrow function |
| 17021 | // using a codemod. Therefore, we don't have to warn about string refs again. |
| 17022 | !(element._owner && element._self && element._owner.stateNode !== element._self)) { |
| 17023 | var componentName = getComponentName(returnFiber.type) || 'Component'; |
| 17024 | |
| 17025 | if (!didWarnAboutStringRefs[componentName]) { |
| 17026 | { |
| 17027 | 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)); |
| 17028 | } |
| 17029 | |
| 17030 | didWarnAboutStringRefs[componentName] = true; |
| 17031 | } |
| 17032 | } |
| 17033 | } |
| 17034 | |
| 17035 | if (element._owner) { |
| 17036 | var owner = element._owner; |
| 17037 | var inst; |
| 17038 | |
| 17039 | if (owner) { |
| 17040 | var ownerFiber = owner; |
| 17041 | |
| 17042 | if (!(ownerFiber.tag === ClassComponent)) { |
| 17043 | { |
| 17044 | 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" ); |
| 17045 | } |
| 17046 | } |
| 17047 | |
| 17048 | inst = ownerFiber.stateNode; |
| 17049 | } |
| 17050 | |
| 17051 | if (!inst) { |
| 17052 | { |
| 17053 | throw Error( "Missing owner for string ref " + mixedRef + ". This error is likely caused by a bug in React. Please file an issue." ); |
| 17054 | } |
| 17055 | } |
| 17056 | |
| 17057 | var stringRef = '' + mixedRef; // Check if previous string ref matches new string ref |
| 17058 | |
| 17059 | if (current !== null && current.ref !== null && typeof current.ref === 'function' && current.ref._stringRef === stringRef) { |
| 17060 | return current.ref; |
| 17061 | } |
| 17062 | |
| 17063 | var ref = function (value) { |
| 17064 | var refs = inst.refs; |
| 17065 | |
| 17066 | if (refs === emptyRefsObject) { |
| 17067 | // This is a lazy pooled frozen object, so we need to initialize. |
| 17068 | refs = inst.refs = {}; |
| 17069 | } |
no test coverage detected