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

Function memo

compat/src/memo.js:11–31  ·  view source on GitHub ↗
(c, comparer)

Source from the content-addressed store, hash-verified

9 * @returns {import('./internal').FunctionComponent}
10 */
11export function memo(c, comparer) {
12 function shouldUpdate(nextProps) {
13 let ref = this.props.ref;
14 if (ref != nextProps.ref && ref) {
15 typeof ref == 'function' ? ref(null) : (ref.current = null);
16 }
17
18 return comparer
19 ? !comparer(this.props, nextProps) || ref != nextProps.ref
20 : shallowDiffers(this.props, nextProps);
21 }
22
23 function Memoed(props) {
24 this.shouldComponentUpdate = shouldUpdate;
25 return createElement(c, props);
26 }
27 Memoed.displayName = 'Memo(' + (c.displayName || c.name) + ')';
28 Memoed._forwarded = Memoed.prototype.isReactComponent = true;
29 Memoed.type = c;
30 return Memoed;
31}

Callers 6

memo.test.jsxFile · 0.90
suspense.test.jsxFile · 0.90
isMemo.test.jsxFile · 0.90
devtools.jsxFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…