MCPcopy
hub / github.com/preactjs/preact / unmount

Function unmount

src/diff/index.js:645–684  ·  view source on GitHub ↗
(vnode, parentVNode, skipRemove)

Source from the content-addressed store, hash-verified

643 * current element is already detached from the DOM.
644 */
645export function unmount(vnode, parentVNode, skipRemove) {
646 let r;
647 if (options.unmount) options.unmount(vnode);
648
649 if ((r = vnode.ref)) {
650 if (!r.current || r.current == vnode._dom) {
651 applyRef(r, NULL, parentVNode);
652 }
653 }
654
655 if ((r = vnode._component) != NULL) {
656 if (r.componentWillUnmount) {
657 try {
658 r.componentWillUnmount();
659 } catch (e) {
660 options._catchError(e, parentVNode);
661 }
662 }
663
664 r.base = r._parentDom = r._globalContext = NULL;
665 }
666
667 if ((r = vnode._children)) {
668 for (let i = 0; i < r.length; i++) {
669 if (r[i]) {
670 unmount(
671 r[i],
672 parentVNode,
673 skipRemove || typeof vnode.type != 'function'
674 );
675 }
676 }
677 }
678
679 if (!skipRemove) {
680 removeNode(vnode._dom);
681 }
682
683 vnode._component = vnode._parent = vnode._dom = UNDEFINED;
684}
685
686/** The `.render()` method for a PFC backing instance. */
687function doRender(props, state, context) {

Callers 2

componentWillUnmountMethod · 0.85

Calls 5

removeNodeFunction · 0.90
_catchErrorMethod · 0.80
applyRefFunction · 0.70
unmountMethod · 0.65
componentWillUnmountMethod · 0.65

Tested by 1

componentWillUnmountMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…