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

Function coerceRef

code/styling/public/app.js:8842–8885  ·  view source on GitHub ↗
(returnFiber, current, element)

Source from the content-addressed store, hash-verified

8840var isArray$1 = Array.isArray;
8841
8842function coerceRef(returnFiber, current, element) {
8843 var mixedRef = element.ref;
8844 if (mixedRef !== null && typeof mixedRef !== 'function' && typeof mixedRef !== 'object') {
8845 {
8846 if (returnFiber.mode & StrictMode) {
8847 var componentName = getComponentName(returnFiber) || 'Component';
8848 if (!didWarnAboutStringRefInStrictMode[componentName]) {
8849 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));
8850 didWarnAboutStringRefInStrictMode[componentName] = true;
8851 }
8852 }
8853 }
8854
8855 if (element._owner) {
8856 var owner = element._owner;
8857 var inst = void 0;
8858 if (owner) {
8859 var ownerFiber = owner;
8860 !(ownerFiber.tag === ClassComponent) ? invariant(false, 'Stateless function components cannot have refs.') : void 0;
8861 inst = ownerFiber.stateNode;
8862 }
8863 !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;
8864 var stringRef = '' + mixedRef;
8865 // Check if previous string ref matches new string ref
8866 if (current !== null && current.ref !== null && current.ref._stringRef === stringRef) {
8867 return current.ref;
8868 }
8869 var ref = function (value) {
8870 var refs = inst.refs === emptyObject ? inst.refs = {} : inst.refs;
8871 if (value === null) {
8872 delete refs[stringRef];
8873 } else {
8874 refs[stringRef] = value;
8875 }
8876 };
8877 ref._stringRef = stringRef;
8878 return ref;
8879 } else {
8880 !(typeof mixedRef === 'string') ? invariant(false, 'Expected ref to be a function or a string.') : void 0;
8881 !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;
8882 }
8883 }
8884 return mixedRef;
8885}
8886
8887function throwOnInvalidObjectType(returnFiber, newChild) {
8888 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