MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / coerceRef

Function coerceRef

code/redux/public/app.js:9093–9136  ·  view source on GitHub ↗
(returnFiber, current, element)

Source from the content-addressed store, hash-verified

9091var isArray$1 = Array.isArray;
9092
9093function coerceRef(returnFiber, current, element) {
9094 var mixedRef = element.ref;
9095 if (mixedRef !== null && typeof mixedRef !== 'function' && typeof mixedRef !== 'object') {
9096 {
9097 if (returnFiber.mode & StrictMode) {
9098 var componentName = getComponentName(returnFiber) || 'Component';
9099 if (!didWarnAboutStringRefInStrictMode[componentName]) {
9100 warning(false, '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 createRef() instead.' + '\n%s' + '\n\nLearn more about using refs safely here:' + '\nhttps://fb.me/react-strict-mode-string-ref', mixedRef, getStackAddendumByWorkInProgressFiber(returnFiber));
9101 didWarnAboutStringRefInStrictMode[componentName] = true;
9102 }
9103 }
9104 }
9105
9106 if (element._owner) {
9107 var owner = element._owner;
9108 var inst = void 0;
9109 if (owner) {
9110 var ownerFiber = owner;
9111 !(ownerFiber.tag === ClassComponent) ? invariant(false, 'Stateless function components cannot have refs.') : void 0;
9112 inst = ownerFiber.stateNode;
9113 }
9114 !inst ? invariant(false, 'Missing owner for string ref %s. This error is likely caused by a bug in React. Please file an issue.', mixedRef) : void 0;
9115 var stringRef = '' + mixedRef;
9116 // Check if previous string ref matches new string ref
9117 if (current !== null && current.ref !== null && current.ref._stringRef === stringRef) {
9118 return current.ref;
9119 }
9120 var ref = function (value) {
9121 var refs = inst.refs === emptyObject ? inst.refs = {} : inst.refs;
9122 if (value === null) {
9123 delete refs[stringRef];
9124 } else {
9125 refs[stringRef] = value;
9126 }
9127 };
9128 ref._stringRef = stringRef;
9129 return ref;
9130 } else {
9131 !(typeof mixedRef === 'string') ? invariant(false, 'Expected ref to be a function or a string.') : void 0;
9132 !element._owner ? invariant(false, 'Element ref was specified as a string (%s) but no owner was set. This could happen for one of the following reasons:\n1. You may be adding a ref to a functional component\n2. You may be adding a ref to a component that was not created inside a component\'s render method\n3. You have multiple copies of React loaded\nSee https://fb.me/react-refs-must-have-owner for more information.', mixedRef) : void 0;
9133 }
9134 }
9135 return mixedRef;
9136}
9137
9138function throwOnInvalidObjectType(returnFiber, newChild) {
9139 if (returnFiber.type !== 'textarea') {

Callers 3

updateElementFunction · 0.70
createChildFunction · 0.70
reconcileSingleElementFunction · 0.70

Calls 4

warningFunction · 0.85
getComponentNameFunction · 0.70
invariantFunction · 0.70

Tested by

no test coverage detected