10 examples of 'react hook unmount' in JavaScript

Every line of 'react hook unmount' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
32export function useUnmount(component: Component, hook: (token: UnmountToken) => void): void {
33 /* istanbul ignore else */
34 if (process.env.IVI_TARGET !== "ssr") {
35 const hooks = component.s;
36 hooks.u = addHook(hooks.u, hook);
37 }
38}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

21export function unmount(props) {
22 return reactLifecycles.unmount(props);
23}
120unmount() {
121 if (this.isClassComponent && this.instance) {
122 this.instance.componentWillUnmount();
123 }
124
125 this.children.forEach(child => {
126 if (child instanceof VNode) {
127 const childInstance = getInstance(child);
128 childInstance.unmount();
129 }
130 });
131
132 if (this.isClassComponent && this.instance) {
133 this.instance.componentDidUnmount();
134 this.instance = null;
135
136 if (this.vnode.ref) {
137 this.vnode.ref(null);
138 }
139 }
140}
78function unmountHook() {
79 act(() => {
80 removeCleanup(unmountHook)
81 unmount()
82 })
83}
18componentWillUnmount() {
19 app.beforeUnmount();
20}
404export function unmount(vnode, parentVNode, skipRemove) {
405 let r;
406 if (options.unmount) options.unmount(vnode);
407
408 if ((r = vnode.ref)) {
409 applyRef(r, null, parentVNode);
410 }
411
412 let dom;
413 if (!skipRemove && typeof vnode.type !== 'function') {
414 skipRemove = (dom = vnode._dom) != null;
415 }
416
417 vnode._dom = vnode._lastDomChild = null;
418
419 if ((r = vnode._component) != null) {
420 if (r.componentWillUnmount) {
421 try {
422 r.componentWillUnmount();
423 } catch (e) {
424 options._catchError(e, parentVNode);
425 }
426 }
427
428 r.base = r._parentDom = null;
429 }
430
431 if ((r = vnode._children)) {
432 for (let i = 0; i < r.length; i++) {
433 if (r[i]) unmount(r[i], parentVNode, skipRemove);
434 }
435 }
436
437 if (dom != null) removeNode(dom);
438}
36unmount(context) {
37 this.context = context;
38
39 this.componentWillUnmount();
40
41 const childContext = this.getChildContext(context),
42 children = this.getChildren();
43
44 children.forEach((child) => child.unmount(childContext));
45
46 super.unmount();
47}
76_beforeUnmount(): void {
77 // при удалении контрола произведем разрегистрацию.
78 if (this._options.defaultActions) {
79 const parents = goUpByControlTree(this._container);
80 this._options.defaultActions.forEach((action) => {
81 for (let i = 0; i < parents.length; i++) {
82 const parent = parents[i];
83 const curAction = this._actions[action.keyCode];
84 if (parent._$defaultActions && parent._$defaultActions[action.keyCode] === curAction) {
85 delete parent._$defaultActions[action.keyCode];
86 } else {
87 break;
88 }
89 }
90 });
91 }
92}
246export function unmountComponent(component) {
247 if (options.beforeUnmount) options.beforeUnmount(component);
248
249 let base = component.base;
250
251 component._disable = true;
252
253 if (component.componentWillUnmount) component.componentWillUnmount();
254
255 component.base = null;
256
257 // recursively tear down & recollect high-order component children:
258 let inner = component._component;
259 if (inner) {
260 unmountComponent(inner);
261 } else if (base) {
262 if (base[ATTR_KEY] && base[ATTR_KEY].ref) base[ATTR_KEY].ref(null);
263
264 component.nextBase = base;
265
266 removeNode(base);
267 collectComponent(component);
268
269 removeChildren(base);
270 }
271
272 if (component.__ref) component.__ref(null);
273}
72export function onCommitFiberUnmount(hook, state, vnode) {
73 // Check if is root
74 if (!shouldFilter(state.filter, vnode)) {
75 let ancestor = getAncestor(state.filter, vnode);
76 if (ancestor && hasVNodeId(vnode) && hasVNodeId(ancestor)) {
77 removeChildFromParent(getVNodeId(ancestor), getVNodeId(vnode));
78 }
79 }
80 recordUnmount(state, vnode);
81}

Related snippets