UNPKG

613 BTypeScriptView Raw
1import * as React from 'react';
2
3/**
4 * Component which prevents updates for children if no props changed
5 */
6function StaticContainer(props: any) {
7 return props.children;
8}
9
10export default React.memo(StaticContainer, (prevProps: any, nextProps: any) => {
11 const prevPropKeys = Object.keys(prevProps);
12 const nextPropKeys = Object.keys(nextProps);
13
14 if (prevPropKeys.length !== nextPropKeys.length) {
15 return false;
16 }
17
18 for (const key of prevPropKeys) {
19 if (key === 'children') {
20 continue;
21 }
22
23 if (prevProps[key] !== nextProps[key]) {
24 return false;
25 }
26 }
27
28 return true;
29});