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

Function coerceRef

code/communication/public/app.js:8877–8920  ·  view source on GitHub ↗
(returnFiber, current, element)

Source from the content-addressed store, hash-verified

8875var isArray$1 = Array.isArray;
8876
8877function coerceRef(returnFiber, current, element) {
8878 var mixedRef = element.ref;
8879 if (mixedRef !== null && typeof mixedRef !== 'function' && typeof mixedRef !== 'object') {
8880 {
8881 if (returnFiber.mode & StrictMode) {
8882 var componentName = getComponentName(returnFiber) || 'Component';
8883 if (!didWarnAboutStringRefInStrictMode[componentName]) {
8884 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));
8885 didWarnAboutStringRefInStrictMode[componentName] = true;
8886 }
8887 }
8888 }
8889
8890 if (element._owner) {
8891 var owner = element._owner;
8892 var inst = void 0;
8893 if (owner) {
8894 var ownerFiber = owner;
8895 !(ownerFiber.tag === ClassComponent) ? invariant(false, 'Stateless function components cannot have refs.') : void 0;
8896 inst = ownerFiber.stateNode;
8897 }
8898 !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;
8899 var stringRef = '' + mixedRef;
8900 // Check if previous string ref matches new string ref
8901 if (current !== null && current.ref !== null && current.ref._stringRef === stringRef) {
8902 return current.ref;
8903 }
8904 var ref = function (value) {
8905 var refs = inst.refs === emptyObject ? inst.refs = {} : inst.refs;
8906 if (value === null) {
8907 delete refs[stringRef];
8908 } else {
8909 refs[stringRef] = value;
8910 }
8911 };
8912 ref._stringRef = stringRef;
8913 return ref;
8914 } else {
8915 !(typeof mixedRef === 'string') ? invariant(false, 'Expected ref to be a function or a string.') : void 0;
8916 !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;
8917 }
8918 }
8919 return mixedRef;
8920}
8921
8922function throwOnInvalidObjectType(returnFiber, newChild) {
8923 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