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

Function applyRef

src/diff/index.js:617–636  ·  view source on GitHub ↗
(ref, value, vnode)

Source from the content-addressed store, hash-verified

615 * @param {VNode} vnode
616 */
617export function applyRef(ref, value, vnode) {
618 try {
619 if (typeof ref == 'function') {
620 let hasRefUnmount = typeof ref._unmount == 'function';
621 if (hasRefUnmount) {
622 // @ts-ignore TS doesn't like moving narrowing checks into variables
623 ref._unmount();
624 }
625
626 if (!hasRefUnmount || value != NULL) {
627 // Store the cleanup function on the function
628 // instance object itself to avoid shape
629 // transitioning vnode
630 ref._unmount = ref(value);
631 }
632 } else ref.current = value;
633 } catch (e) {
634 options._catchError(e, vnode);
635 }
636}
637
638/**
639 * Unmount a virtual node from the tree and apply DOM changes

Callers 3

diffChildrenFunction · 0.90
commitRootFunction · 0.70
unmountFunction · 0.70

Calls 3

_unmountMethod · 0.80
_catchErrorMethod · 0.80
refFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…