MCPcopy
hub / github.com/facebook/react / commitAttachRef

Function commitAttachRef

packages/react-reconciler/src/ReactFiberCommitEffects.js:756–823  ·  view source on GitHub ↗
(finishedWork: Fiber)

Source from the content-addressed store, hash-verified

754}
755
756function commitAttachRef(finishedWork: Fiber) {
757 const ref = finishedWork.ref;
758 if (ref !== null) {
759 let instanceToUse;
760 switch (finishedWork.tag) {
761 case HostHoistable:
762 case HostSingleton:
763 case HostComponent:
764 instanceToUse = getPublicInstance(finishedWork.stateNode);
765 break;
766 case ViewTransitionComponent: {
767 if (enableViewTransition) {
768 const instance: ViewTransitionState = finishedWork.stateNode;
769 const props: ViewTransitionProps = finishedWork.memoizedProps;
770 const name = getViewTransitionName(props, instance);
771 if (instance.ref === null || instance.ref.name !== name) {
772 instance.ref = createViewTransitionInstance(name);
773 }
774 instanceToUse = instance.ref;
775 break;
776 }
777 instanceToUse = finishedWork.stateNode;
778 break;
779 }
780 case Fragment:
781 if (enableFragmentRefs) {
782 const instance: null | FragmentInstanceType = finishedWork.stateNode;
783 if (instance === null) {
784 finishedWork.stateNode = createFragmentInstance(finishedWork);
785 }
786 instanceToUse = finishedWork.stateNode;
787 break;
788 }
789 // Fallthrough
790 default:
791 instanceToUse = finishedWork.stateNode;
792 }
793 if (typeof ref === 'function') {
794 if (shouldProfile(finishedWork)) {
795 try {
796 startEffectTimer();
797 finishedWork.refCleanup = ref(instanceToUse);
798 } finally {
799 recordEffectDuration(finishedWork);
800 }
801 } else {
802 finishedWork.refCleanup = ref(instanceToUse);
803 }
804 } else {
805 if (__DEV__) {
806 // TODO: We should move these warnings to happen during the render
807 // phase (markRef).
808 if (typeof ref === 'string') {
809 console.error('String refs are no longer supported.');
810 } else if (!ref.hasOwnProperty('current')) {
811 console.error(
812 'Unexpected ref object provided for %s. ' +
813 'Use either a ref-setter function or React.createRef().',

Callers 1

safelyAttachRefFunction · 0.85

Calls 10

getPublicInstanceFunction · 0.90
getViewTransitionNameFunction · 0.90
createFragmentInstanceFunction · 0.90
startEffectTimerFunction · 0.90
recordEffectDurationFunction · 0.90
shouldProfileFunction · 0.85
refFunction · 0.85
errorMethod · 0.65

Tested by

no test coverage detected