MCPcopy Create free account
hub / github.com/microsoft/SandDance / unmountComponentAtNode

Function unmountComponentAtNode

docs/external/js/react-dom.development.js:24992–25043  ·  view source on GitHub ↗
(container)

Source from the content-addressed store, hash-verified

24990 return legacyRenderSubtreeIntoContainer(parentComponent, element, containerNode, false, callback);
24991 }
24992 function unmountComponentAtNode(container) {
24993 if (!isValidContainer(container)) {
24994 {
24995 throw Error( "unmountComponentAtNode(...): Target container is not a DOM element." );
24996 }
24997 }
24998
24999 {
25000 var isModernRoot = isContainerMarkedAsRoot(container) && container._reactRootContainer === undefined;
25001
25002 if (isModernRoot) {
25003 error('You are calling ReactDOM.unmountComponentAtNode() on a container that was previously ' + 'passed to ReactDOM.createRoot(). This is not supported. Did you mean to call root.unmount()?');
25004 }
25005 }
25006
25007 if (container._reactRootContainer) {
25008 {
25009 var rootEl = getReactRootElementInContainer(container);
25010 var renderedByDifferentReact = rootEl && !getInstanceFromNode$1(rootEl);
25011
25012 if (renderedByDifferentReact) {
25013 error("unmountComponentAtNode(): The node you're attempting to unmount " + 'was rendered by another copy of React.');
25014 }
25015 } // Unmount should not be batched.
25016
25017
25018 unbatchedUpdates(function () {
25019 legacyRenderSubtreeIntoContainer(null, null, container, false, function () {
25020 // $FlowFixMe This should probably use `delete container._reactRootContainer`
25021 container._reactRootContainer = null;
25022 unmarkContainerAsRoot(container);
25023 });
25024 }); // If you call unmountComponentAtNode twice in quick succession, you'll
25025 // get `true` twice. That's probably fine?
25026
25027 return true;
25028 } else {
25029 {
25030 var _rootEl = getReactRootElementInContainer(container);
25031
25032 var hasNonRootReactChild = !!(_rootEl && getInstanceFromNode$1(_rootEl)); // Check if the container itself is a React root node.
25033
25034 var isContainerReactRoot = container.nodeType === ELEMENT_NODE && isValidContainer(container.parentNode) && !!container.parentNode._reactRootContainer;
25035
25036 if (hasNonRootReactChild) {
25037 error("unmountComponentAtNode(): The node you're attempting to unmount " + 'was rendered by React and is not a top-level container. %s', isContainerReactRoot ? 'You may have accidentally passed in a React root node instead ' + 'of its container.' : 'Instead, have the parent component update its state and ' + 'rerender in order to remove this component.');
25038 }
25039 }
25040
25041 return false;
25042 }
25043 }
25044
25045 function createPortal(children, containerInfo, // TODO: figure out the API for cross-renderer implementation.
25046 implementation) {

Callers

nothing calls this directly

Calls 8

isValidContainerFunction · 0.85
isContainerMarkedAsRootFunction · 0.85
getInstanceFromNode$1Function · 0.85
unbatchedUpdatesFunction · 0.85
unmarkContainerAsRootFunction · 0.85
errorFunction · 0.70

Tested by

no test coverage detected